Nested Loop Registed Variable

28 views
Skip to first unread message

Abhishek R.

unread,
Jul 8, 2015, 8:21:33 PM7/8/15
to ansible...@googlegroups.com
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

Abhishek R.

unread,
Jul 9, 2015, 5:06:10 PM7/9/15
to ansible...@googlegroups.com
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 
Reply all
Reply to author
Forward
0 new messages