item2[‘ipv4-address’] is defined and item2[‘ipv4-address’] == ip
debug:
msg: “Network Object exists with name [{{obj_name}}]”
when: item_ip_exists is defined
debug:
msg: " Network Object ({{ip}}) will be created"
when: item_ip_exists is not defined
I am facing issue for set_fact variable like obj_name and item_ip_exists
so when loop runs on first item and if object is present so it set both the variable (obj_name and item_ip_exists ) and print the correct debug messages.
but when 2nd item executed and there if object is not present so it is printing the wrong debug message due to the set_fact variables( obj_name and item_ip_exists) which has already the value from the first items execution
so how i can restrict the scope of set_fact variables ( obj_name and item_ip_exists ) so when second item execute the variables take the value from there not from previously set_fact values.
I am totally stuck here.
Please help me. Thanks in advance.
how to resolve this issue.I guess we can not restrict the scope of set_fact variable we can set the value null but in my case ,i wanted the set_facts variables value is undefined so when the 2nd item of loop executed so it will get the value from that execution.
can any one suggest any-other way to accomplish my task.
Hints:
* Does your problem depend on the included role? If not, remove it.
* Does your problem depend on the uri module? If not, remove it.
* Create the lists as simple as possible to demonstrate the problem
It seems that your problem might be limited to a single task. Please help us
to help you.
Thanks Vladmir for replying on my post.
in my question inculd_role and the validation task script is necessary to understand my question.
so basically in my playbook i am calling a role and looping that role with two lists mserver and domain
. I am performing validation of object on firewall using the firewall api and getting the r present object in “check_host_result.json.object” and then i write the task to check object is present .where I am using set_fact variable item_ip_exists and item_name. my problem is when list’s first item executed then both set_fact variables have the values but when lists second item executed and if object is not present on there that task is referencing the previous set_fact varaibles value and printing the debug message incorrect.
below is the lists
mserver: [1.1.1.1,2.2.2.2]
doamin: [3.3.3.3,4.4.4.4]