How to Create Ansible Playbook to Install Apache Server
To Create Ansible Playbook to Install Apache Server
Apache is a web server that is used on the Internet. It is easy to set up and configure on Linux distributions including Ubuntu and Debian, as it comes in the package repositories and includes a default configuration that works out of the box. This video will cover the installation of an apache server using Ansible.
Installation process:
Create a playbook to isntall apache server on your host machine
[root@localhost ansible]# vim httpd.yml
After creating playbook now let’s run this using the following command
[root@localhost ansible]# ansible-playbook httpd.yml
PLAY [httpd is there] *********************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************
ok: [192.168.6.111]
TASK [ensure httpd is installed] **********************************************************************************************
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop
to supply multiple items and specifying `pkg: "{{item}}"`, please use `pkg: ['nano', 'httpd']` and remove the loop. This
feature will be removed from ansible-base in version 2.11. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
changed: [192.168.6.111] => (item=['nano', 'httpd'])
PLAY RECAP ********************************************************************************************************************
192.168.6.111 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Now I am going to uninstall the httpd from our host machine using the following playbook
[root@localhost ansible]# vim httpd.yml
And now run this playbook to uninstall the apache from the host machine.
[root@localhost ansible]# ansible-playbook httpd.yml
PLAY [httpd is there] *********************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************
ok: [192.168.6.111]
TASK [ensure httpd is installed] **********************************************************************************************
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop
to supply multiple items and specifying `pkg: "{{item}}"`, please use `pkg: ['nano', 'httpd']` and remove the loop. This
feature will be removed from ansible-base in version 2.11. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
changed: [192.168.6.111] => (item=['nano', 'httpd'])
PLAY RECAP ********************************************************************************************************************
192.168.6.111 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Now in case if you want to install multiple application packages on your host machine using ansible
Now run this playbook to install apache and nano to install on your host machine
[root@localhost ansible]# ansible-playbook httpd.yml%%
PLAY [httpd is there] *********************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************
ok: [192.168.6.111]
TASK [ensure httpd is installed] **********************************************************************************************
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop
to supply multiple items and specifying `pkg: "{{item}}"`, please use `pkg: ['nano', 'httpd']` and remove the loop. This
feature will be removed from ansible-base in version 2.11. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.
changed: [192.168.6.111] => (item=['nano', 'httpd'])
PLAY RECAP ********************************************************************************************************************
192.168.6.111 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
With this method installation of apache on ansible host machine comes to an end.
Comments ( 0 )
No comments available