2-Day2-2-NotifyAndHandlers
Ansible Playbook: Notify and handlers in ansible
Objective
Instructions
<!DOCTYPE html> <html> <head> <title>Hello from Ansible on CentOS with Apache!</title> </head> <body> <h1>Welcome to my Ansible-powered website!</h1> <p>This is a sample webpage created using Ansible.</p> </body> </html>
nano nginx-playbook.yml--- - hosts: centos_servers become: yes tasks: - name: Install apache on CentOS yum: name: httpd state: present - name: Copy HTML file to the server copy: src: /path/to/your/local/index.html dest: /var/www/html/index.html notify: - Restart Apache if content changes - name: Start apache service systemd: name: httpd enabled: yes state: started handlers: - name: Restart Apache if content changes systemd: name: httpd state: restarted listen: "content_changed"
ansible-playbook -i inventory nginx-playbook.yml
Notify and Handlers Explained
Testing Notify and Handlers
Objective
Instructions
Conclusion
Last updated