- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
03-24-2020 02:04 AM - edited 03-24-2020 02:05 AM
Hello,
I have a simple playbook adding/removing tags:
---
- name: 'Palo Alto PAN OS: Create a new tag object.'
hosts: all
connection: local
gather_facts: true
collections:
- paloaltonetworks.panos
pre_tasks:
- name: Get the system information.
include_vars: ./vars/provider.yml
no_log: 'no'
tasks:
- name: Create a tag object.
when: operation == "create"
panos_tag_object:
provider: '{{ provider }}'
name: '{{ tag_name }}'
color: '{{ tag_color }}'
comments: '{{ tag_comment }}'
- name: Remove a tag object.
when: operation == "remove"
panos_tag_object:
provider: '{{ provider }}'
name: '{{ tag_name }}'
color: '{{ tag_color }}'
state: absent
The '/vars/provider.yml' looks like this:
provider:
ip_address: '2000.iaas.company.com'
api_key: MY876API9787KEY
I would like to have two more 'provider' values and let the playbook to make a choice depending on the "ansible_hostname" or IP address. I can't figure it out. Can someone help? Maybe there is a better approach?
Regards,
Michael
03-25-2020 04:50 PM
You need to make a list of provider dicts, then loop over that:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#standard-loops
03-25-2020 04:50 PM
You need to make a list of provider dicts, then loop over that:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_loops.html#standard-loops
03-25-2020 10:59 PM
Thanks. I found out It also possible to use host_vars to separate variables for different hosts.
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!