Update apt cache The first task updates the apt cache on the server to ensure that the latest version of packages is available for installation.
Install Nginx The second task installs Nginx on the server using the apt module.
Copy sample webpage The third task copies a sample webpage from your local machine to the remote server using the copy module. This is the webpage that will be served by Nginx.
Restart Nginx service The final task restarts the Nginx service to ensure that the changes take effect.
- name: Install Nginx and deploy sample webpage
hosts: server_3
become: true
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install Nginx
apt:
name: nginx
state: present
- name: Copy sample webpage
copy:
src: /home/ubuntu/ansible/webpage.html
dest: /var/www/html/index.html
mode: "0644"
- name: Restart Nginx service
service:
name: nginx
state: restarted
ansible-playbook webpage.yml