Wednesday, 10 July 2019

Ansible playbook accessing variables from var file



---
- hosts: raghu
  vars_files:
      - firstplaybookvars.yml
  tasks:
      - name: Create file
        file:
            path: "{{ path }}"
            state: "{{ state }}"
        notify:
           - restart apache

  handlers:
      - name: restart apache
        service: name=httpd state=started

---
path: /tmp/raghu
state: touch

Ansible playbook with notify and handlers example


---
- hosts: raghu
  vars:
      path: /tmp/raghu
      state: touch
  tasks:
      - name: Create file
        file:
            path: "{{ path }}"
            state: "{{ state }}"
        notify:
           - restart apache

  handlers:
      - name: restart apache
        service: name=httpd state=started

Ansible playbook loop with condition example



  tasks:
      - name: Create file
        file:
            path: "{{ item.path }}"
            state: "{{ item.state }}"
        loop:
            - { path: '/tmp/ragx' , state: 'touch' }
        when: item.path == '/tmp/raghu'

Ansible playbook loop example



  tasks:
      - name: Create file
        file:
            path: "{{ item.path }}"
            state: "{{ item.state }}"
        loop:
            - { path: '/tmp/raghu' , state: 'touch' }
            - { path: '/opt/raghu' , state: 'touch' }

Ansible playbook vars example



---
- hosts: raghu
  vars:
      path: /tmp/raghu
      state: touch
  tasks:
      - name: Create file
        file:
            path: "{{ path }}"
            state: "{{ state }}"

Ansible playbook to create folder



---
- hosts: raghu

  tasks:
      - name: Create file
        file:
            path: /tmp/raghu
            state: touch

ansible vault



ansible-vault create vault.yml
ansible-vault view vault.yml
ansible-vault edit vault.yml
ansible-vault decrypt vault.yml
ansible-vault rekey vault.yml

ansible-playbook site.yml --ask-vault-pass
ansible-playbook site.yml --vault-password-file ~/.vault_pass.txt

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...