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

How to do it...

  1. Create a new Ansible playbook called ansible_tags.yml, as shown here:
---
- name: Using Ansible Tags
hosts: cisco
gather_facts: no
tasks:
- name: Print OSPF
debug:
msg: "Router {{ hostname }} will Run OSPF"
tags: [ospf, routing]

- name: Print BGP
debug:
msg: "Router {{ hostname }} will Run BGP"
tags:
- bgp
- routing

- name: Print NTP
debug:
msg: "Router {{ hostname }} will run NTP"
tags: ntp
  1. Run the playbook as shown here:
$ ansible-playbook ansible_tags.yml -i hosts --tags routing
  1. Run the playbook again, this time using tags, as shown here:
$ ansible-playbook ansible_tags.yml -i hosts --tags ospf

$ ansible-playbook ansible_tags.yml -i hosts --tags routing