Ansible Notes – Aug Batch Online – Notes – Day -3
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
ansible web -i inventory -m apt -a"name=apache2 state=present" -u ubuntu -k -b
ansible web -i inventory -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu -k -b
ansible web -i inventory -m service -a"name=apache2 state=started" -u ubuntu -k -b
ansible web -i inventory -m apt -a"name=apache2 state=present" -u ubuntu -k -b
ansible web -i inventory -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu -k -b
ansible web -i inventory -m service -a"name=apache2 state=started" -u ubuntu -k -b
ansible web -i inventory -m apt -a"name=apache2 state=present" -u ubuntu -k -b
ansible web -i inventory -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu -k -b
ansible web -i inventory -m service -a"name=apache2 state=started" -u ubuntu -k -b
Ansible Playbook
================================
YAML
Contains PLAY
PLAY
---------------------------
Hosts: localhost OR Groupname from inventory
TAsKS:
Task1 == Mode1 n Its Param
Task2 == Mode1 n Its Param
Task3 == Mode1 n Its Param
Task4 == Mode1 n Its Param
==========================================
---
- name: Update web servers
hosts: localhost
tasks:
- name: Install apache httpd (state=present is optional)
ansible.builtin.apt:
name: apache2
state: present
- name: Copy file with owner and permissions
ansible.builtin.copy:
src: index.html
dest: /var/www/html/index.html
- name: Start service httpd, if not started
ansible.builtin.service:
name: apache2
state: started
===============================
ansible-playbook web.yaml
ansible-playbook -C web.yaml
ansible-playbook -C web.yaml -vvvvvvv
ansible-playbook -i inventory web.yaml -u ubuntu -k -b
==================================================
How to add Vars | Template | Handlers | Cond | Loop