Handson 1: playbook vi test.yml
type i (insert mode)
---
hosts: all remote_user: ubuntu sudo: yes
tasks:
name: Installs nginx web server
apt: pkg=nginx state=installed update_cache=true notify:
- start nginx
handlers:
name: start nginx
service: name=nginx state=started
click escape and then type :wq (to write file and quit editor) step:2
execute playbook:
ansible-playbook -i myhosts test.yml
Handson 2: above code replace nginx with apache2 for loops handson Handson 3: when clause:
---
hosts: all remote_user: ubuntu sudo: yes
tasks:
name: Check that the somefile.j2 exists stat:
path: /somefile.j2 register: stat_result
name: Copy the template, if it doesnt exist already template:
src: somefile.j2
dest: /home/ubuntu/somefile.j2 when: stat_result.stat.exists == False
Post a Comment