Source: juniordevops.medium.com

Deploying NGINX locally using Ansible

Category: Software, nginx, yaml, ansible

As an example of Ansible in action, NGINX can be deployed using a Ansible Playbook.

Steps will be spelled out on how NGINX will be deployed, on all relevant servers, using a Playbook written in YAML named playbook_nginx_install.yaml : The YAML file starts with three dashes — — starting the first block. Nested one level, as indicated by a da sh - within the block is the hosts: statement, representing the server grouping for the Playbook to target, which would be the group local in this example, containing only localhost.

Indented one level deeper would be the name: statement, representing the application needing installation; the state: statement represents the task to be done, in this case the module will check to see if NGINX is installed, and will do so if not, so the value will be set to present: The same thing can be repeated for the service module, which will start the NGINX service. Nested within the service module is the name: statement, representing the application needing to be manipulated; the state: statement represents the action to be performed, in this case to start the service, the value will be set to started: Running the Playbook demonstrates that the install of NGINX is successful: Since Ansible is idempotent, running the Playbook again will perform no changes: Based on the created playbook_nginx_install.yaml Playbook, a version can be created, named playbook_nginx_uninstall.yaml, that would do the mirror.

Related Articles