June 2017
Intermediate to advanced
446 pages
10h 10m
English
The when clause is useful when you need to check the output from the result and act accordingly. Let's look at a simple example of its usage in chapter5_1.yml:
--- - name: IOS Command Output hosts: "iosv-devices" gather_facts: false connection: local vars: cli: host: "{{ ansible_host }}" username: "{{ username }}" password: "{{ password }}" transport: cli tasks: - name: show hostname ios_command: commands: - show run | i hostname provider: "{{ cli }}" register: output - name: show output when: '"iosv-2" in "{{ output.stdout }}"' debug: msg: '{{ output }}'
We have seen all the elements in this playbook before in Chapter 4, Python Automation Framework – Ansible Basics; the only difference is on the second task, as we are using ...
Read now
Unlock full access