Network Automation Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Create a new playbook called ansible_cond.yml inside the ch1_ansible folder.
  2. Place the following content in the new playbook as shown here:
---
- name: Using conditionals
hosts: all
gather_facts: no
tasks:
- name: Run for Edge nodes Only
debug:
msg: "Router name is {{ hostname }}"
when: "'edge' in group_names"

- name: Run for Only MX1 node
debug:
msg: "{{ hostname }} is running {{ os }}"
when:
- inventory_hostname == 'mx1'
  1. Run the playbook as shown here:
$ ansible-playbook -i hosts ansible_cond.yml