How to create a set of different "provider" values depending on 'ansible_hostname'?

Reply
Highlighted
L1 Bithead

How to create a set of different "provider" values depending on 'ansible_hostname'?

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

Tags (1)

Accepted Solutions
Highlighted
L4 Transporter

Re: How to create a set of different "provider" values depending on 'ansible_hostname'?


All Replies
Highlighted
L4 Transporter

Re: How to create a set of different "provider" values depending on 'ansible_hostname'?

Highlighted
L1 Bithead

Re: How to create a set of different "provider" values depending on 'ansible_hostname'?

Thanks. I found out It also possible to use host_vars to separate variables for different hosts.

Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

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 Live Community as a whole!

The Live Community thanks you for your participation!