Ansible Loops & conditions Flashcards

1
Q

Can you give an example of using “when” condition in playbook?

A
  • name: Install Softwares
    hosts: all
    vars:
    packages:
    - name: nginx
    required: True
    - name: mysql
    required: True
    - name: apache
    required: False
    tasks:
    - name: Install “{{ item.name }}” on Debian
    apt:
    - name: “{{ item.name }}”
    state: present
    when: item.required == True
    loop: {{ packages }}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly