Team,
I would like to use the variable i got from one ansible task to another task where hosts are different.
Please help me use the variable to use it on another task!!
Team,
I would like to use the variable i got from one ansible task to another task where hosts are different.
Please help me use the variable to use it on another task!!
When i try to use/inoke on another task, i get error as sec_tunnel_ip is undefined.
Those variables are scoped to a host, so they’re not available to other hosts.
A common trick is to assign them to a dummy host and access them that way.
Thanks a lot, Dick Visser, I just wanted to access it, even with a dummy hostname is ok. let me try that.
One more help needed, When I try to do regex to get the ip output, it comes along with the unicode characters such as - [u’
how to eliminate it while grepping it through regex_search itself.
Actual output: “- [u’172.16.121.6’]\n”
I want it to be(expected): 172.16.121.6
Output:
You're sending only the output of the debug task with the regex_search
applied to the output.stdout variable.
We need to see the output.stdout variable before you mangled it.
Hi Dick, Below is the complete output of the playbook,
[root@tower1 temp_play]# ansible-playbook testplay2.yml -i /etc/ansible/temp_play/hosts
PLAY [Get the secondary router tunnel ip address] *****************************************************************
TASK [Obtain secondary tunnel interface ip address] ***************************************************************
ok: [172.16.12.1]
TASK [debug] ******************************************************************************************************
ok: [172.16.12.1] => {
“msg”: [
“Internet address is 172.16.121.6/32”
]
}
TASK [set_fact] ***************************************************************************************************
ok: [172.16.12.1]
TASK [debug] ******************************************************************************************************
ok: [172.16.12.1] => {
“msg”: {
“ansible_facts”: {
“intf”: “- [u’172.16.121.6’]\n”
},
“changed”: false,
“failed”: false
}
}
PLAY RECAP ********************************************************************************************************
172.16.12.1 : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[root@tower1 temp_play]#
Thanks,
Charles Daniel
Hi Dick, Below is the complete output of the playbook,
[root@tower1 temp_play]# ansible-playbook testplay2.yml -i /etc/ansible/temp_play/hosts
PLAY [Get the secondary router tunnel ip address] *****************************************************************
TASK [Obtain secondary tunnel interface ip address] ***************************************************************
ok: [172.16.12.1]TASK [debug] ******************************************************************************************************
ok: [172.16.12.1] => {
"msg": [
"Internet address is 172.16.121.6/32 <http://172.16.121.6/32>"
]
}
Hello Charles,
the output looks like a string, so the map filter doesn't makes sense here.
Please try:
{{output.stdout | regex_search('(([0-9]+(.)[0-9]+(.)[0-9]+(.)[0-9]+))') }}
Regards
Racke
Try “{{ output.stdout[0] }}” on the debug task
returns error as a pattern not matching!!.
TASK [debug] ******************************************************************************************************
ok: [172.16.12.1] => {
“hostvars[‘SEC_HOST’][‘sec_tunnel_ip1’]”: “- [None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]\n”
}
no need for dummy, just use hostvars[<host that has var>][<varname>]
if you set the vars on a group you can
hostvars[group[<groupname>][0]][<varname>] ( 0 is 'first host in
group, but you can use random index <= # of hosts in group)
Thanks Brian