Ansible playbook
Ansible autocomplete
sudo apt install python3-argcomplete -y
- Now appending the following to the file ~/.bashrc
eval "$(register-python-argcomplete ansible)"
eval "$(register-python-argcomplete ansible-config)"
eval "$(register-python-argcomplete ansible-playbook)"
eval "$(register-python-argcomplete ansible-galaxy)"
- now in the current terminal
source ~/.bashrc
- when you are executing ansible commands we can use tab to view options
Execution
ansible-playbook --syntax-check -i hosts <playbook>.yaml
- Ansible also has dry run (which doesnot work in certain cases)
ansible-playbook --check --inventory hosts apache.yaml
- To execute ansible playbook
ansible-playbook -i hosts <playbook>.yaml

Reading ansible playbook execution.
- Ansible adds an extra task to collect facts
- Any task will result with
- ok: Desired state is met
- changed: Task was executed
- failed: Task failed
Lets continue playbook for apache2
sudo systemctl start apache2
sudo systemctl enable apache2
sudo apt install php libapache2-mod-php -y
- copy the test.php file
- Refer Here for the changes done.
Exercise:
- Install nginx , php and use the same test page.
Like this:
Like Loading...