I have in the inventory file :
server1-prod cname=server1_prod
server2-prdo cname=server2_prod
......
.....
in my role i have in vars a file like this for every server: server1_pprod server2_pp etc ... <== this is the name of the files which are in role/vars/
cron:
job1:
name: "******"
job: "********"
minute: "0"
hour: "0"
day: "*"
month: "*"
weekday: "*"
disabled: "no"
backup: yes
job: "*******************************"
cron_special_time:
job1:
name: "******"
special_time: "reboot"
disabled: "yes"
backup: yes
job: "*****"
job2:
name: "*****"
special_time: "reboot"
disabled: "yes"
backup: yes
job: "*****"
I include the file with this task so that i have a variabl serveX_prod for every file serverX_prod which corespend to a serveX-prod in the inventory
- name: Loading system cron file to vars
include_vars:
file: "{{ cname }}"
name: "{{ cname }}"
then i access the variable in a task :
- name: Add system cron jobs
cron:
.....
......
with_dict:
- "{{ vars[cname].cron }}"
when: "{{ vars[cname].cron }}" is defined
you see the problem is i cant put " " in when sentence and i cant get a dynamic variable without " " , i am confused