Discussion:
[ansible-project] Nested Loop Registed Variable
Abhishek R.
2015-07-09 00:19:59 UTC
Permalink
Hi folks,

Need some help related to registered variables.

The first task in my playbook performs some operations over a nested loop
and I'm registering a variable for its results. The variable looks like
this -

"n_init": {
"changed": true,
"failed": true,
"msg": "One or more items failed.",
"results": [
{
"changed": true,
----
"item": [
"host1.abc.com",
"1098"
],
----
},
{
"changed": true,
----
"item": [
"host2.abc.com",
"1098"
],
----
},
----
{
"changed": true,
----
"item": [
"host10.abc.com",
"1098"
],
----
}
]
}

In my second task, I need to execute a script and need to pass two
parameters to it, both derived from the above variable. The two parameters
should have contents like this -

param1 (string) - "host1.abc.com:host2.abc.com:...:host10.abc.com"
param2 (json array) -
[{"host":"host1.abc.com","port":"1098"},{"host":"host2.abc.com","port":"1098"},...,{"host":"host10.abc.com","port":"1098"}]

I've tried out few Jinja2 filters and Ansible looping constructs, but am
unable to get these values off the registered variable. Any suggestions?

Thanks in advance

Regards
Abhishek
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e81f8b3c-4e55-421b-81a2-b441b97a734a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Abhishek R.
2015-07-09 21:06:10 UTC
Permalink
Ok. Did not realize that we can use Jinja2 statement blocks right along
with the modules and it doesn't always have to just a variable expression.
Was able to do this by templating.

Regards
Abhishek
Post by Abhishek R.
Hi folks,
Need some help related to registered variables.
The first task in my playbook performs some operations over a nested loop
and I'm registering a variable for its results. The variable looks like
this -
"n_init": {
"changed": true,
"failed": true,
"msg": "One or more items failed.",
"results": [
{
"changed": true,
----
"item": [
"host1.abc.com",
"1098"
],
----
},
{
"changed": true,
----
"item": [
"host2.abc.com",
"1098"
],
----
},
----
{
"changed": true,
----
"item": [
"host10.abc.com",
"1098"
],
----
}
]
}
In my second task, I need to execute a script and need to pass two
parameters to it, both derived from the above variable. The two parameters
should have contents like this -
param1 (string) - "host1.abc.com:host2.abc.com:...:host10.abc.com"
param2 (json array) - [{"host":"host1.abc.com","port":"1098"},{"host":"
host2.abc.com","port":"1098"},...,{"host":"host10.abc.com","port":"1098"}]
I've tried out few Jinja2 filters and Ansible looping constructs, but am
unable to get these values off the registered variable. Any suggestions?
Thanks in advance
Regards
Abhishek
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/82d4857e-916a-43e8-9447-757fae4b5ab7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...