Need variable that matches certain group-host run

13 views
Skip to first unread message

Naftali Burnham

unread,
Mar 12, 2018, 7:01:59 AM3/12/18
to Ansible Project
Hi,
   Im not finding exactly what Im trying to do, or maybe Im not getting how to accomplish this.  Ive been playing with different ways to do this.

I need so set some different variable in a template. 

this is content of j2 file.

---
monitoring
:
 
-
    lpmonitoring
: {{ item.mon }}
    lpenvironment
: {{ item.env }}

When I have a run that pulls the above template I need that item.mon and item.env variable to be set accoring to which hosts: GROUP is running....
as in when I run the playbook against the hosts in group P1-CI I want the variables to be item.mon=P1 and item.env=CI   and when it runs in P1-QA i want to  variable to be item.mon=P1 item.env=QA


---
- name: generate lpmonitoringYaml facter file
  hosts
: P1-CI,P1-QA





Thanks very much



Naftali Burnham

unread,
Mar 13, 2018, 5:10:52 AM3/13/18
to Ansible Project
Hi I found my answer ...

Because I needed default variable to be attached to a specific host/inventory group during that group run I needed to add them into the inventory file itself.... for this case it works perfect.

[P1-CI]
server01

#####################################################
### variables that must be applied per host group ###
#####################################################

[P1-CI:vars]
data_mon='P1'
data_env='CI'


On Monday, March 12, 2018 at 1:01:59 PM UTC+2, Naftali Burnham wrote:
Hi,
   Im not finding exactly what Im trying to do, or maybe Im not getting how to accomplish this.  Ive been playing with different ways to do this.

I need so set some different variable in a template. 

this is content of j2 file.

---
monitoring
:
 
-
    lpmonitoring
: {{ data_mon }}
    lpenvironment
: {{ data_env }}

Reply all
Reply to author
Forward
0 new messages