... role "x" that uses two default vars:
(roles/x/defaults/main.yml)
server1var: server1
server2var: server2
... playbook ...
vars:
server1var: server3
server2var: server4
tasks:
- include_role:
name: x
Is it possible that the tasks executed by "include_role" take the vars from
the current playbook?
I have found out that the problem is caused by a random generator. Its not the include_role task itself (thats why I opened the question in first place)
I have two lists and building a new list excluding the items from list1 (which is something like “server1”, “server2”…)
vars:
list1:
“{{file_content.server1var}}”
“{{file_content.server2var}}”
list2:
server1
server2
server3
server4
server5
server6
tasks:
name: generate newlist based on difference between list1 and list2
set_fact:
newlist: “{{ list2 | difference(list1) }}”
name: set fact random2
set_fact:
randomserver: “{{ newlist | random }}”
##This for example shows me server2 when i run the play one time###
name: show randomnode
debug:
msg: “{{randomnode}}”
…
##Now im using that randomnode variable for the include_role##
name: ping the servers
ping:
when: inventory_hostname == server1var or inventory_hostname == server2var
###Now im expecting that “server2var” will be “server2”, but its kinda random what happens there###
###For example: sometimes its get executed on 4 servers, 3 servers, 2 servers, 1 server. The only Server that is consistent is server1var (whhich is “server1”)###
Maybe you have an idea what might cause that problem?
I saw in your github examples, that you already used random filter.