You know what- I answered your title, not your question. If you don't
want to have to try and persist things between plays, you might have
more luck with something like this:
- hosts: myhosts
tasks:
- shell: echo things
local_action: true
register: new_ips
- shell: echo other things {{new_ips}}
but there's nothing in your example that seems to necessitate anything
that you're doing.
On Mon, Aug 25, 2014 at 11:14 PM, Imran Khan <[email protected]> wrote:
> {{hostvars[groups['localhost'].new_ips.results.stdout}}
> Gives the following error: One or more undefined variables: 'dict object'
> has no attribute 'localhost'
>
>
>
> On Monday, August 25, 2014 10:37:57 PM UTC-7, Henry Finucane wrote:
>>
>> Probably something like
>>
>> hostvars[groups['webservers']|first].new_ips
>>
>> On Mon, Aug 25, 2014 at 10:35 PM, Imran Khan <[email protected]> wrote:
>> > Hello, is it possible to do the following
>> >
>> > - hosts: localhost
>> > gather_facts: False
>> >
>> > tasks:
>> > #
>> > #
>> > - name: create new IP Addresses
>> > #debug: msg={{resultip.stdout.split('.')[3]}}
>> > shell: echo "{{ ServerIP.split('.')[0] }}.{{
>> > ServerIP.split('.')[1] }}.{{ ServerIP.split('.')[2] }}.{{ item }}"
>> > with_items: result.stdout_lines
>> > register: new_ips
>> > #
>> > #
>> >
>> > - hosts: myhosts
>> > gather_facts: False
>> > #
>> > #
>> > - name: Replace ServerIP in config_file on myhosts
>> > shell: cd /home/imran/Desktop/tobefetched; sed -i
>> > '/{{String1}}/ c
>> > "ServerIP" ':' "{{hostvars.localhost.new_ips.{{item}}}}" ' config_file
>> > with_items: hostvars.localhost.new_ips.stdout_lines
>> > #
>> > #
>> >
>> > Summary: I just want to access the individual entries of new_ips
>> > (defined in
>> > localhost) in hosts: myhosts in a loop. How can I do that?
>> >
>> > Sample Output of what is saved in new_ips, when array size is 2:
>> >
>> > TASK: [Checking to see if new IPs were stored]
>> > ********************************
>> > ok: [localhost] => {
>> > "new_ips": {
>> > "changed": true,
>> > "msg": "All items completed",
>> > "results": [
>> > {
>> > "changed": true,
>> > "cmd": "echo \"11.11.4.74\"",
>> > "delta": "0:00:00.001776",
>> > "end": "2014-08-25 22:28:46.163851",
>> > "invocation": {
>> > "module_args": "echo \"11.11.4.74\"",
>> > "module_name": "shell"
>> > },
>> > "item": "74",
>> > "rc": 0,
>> > "start": "2014-08-25 22:28:46.162075",
>> > "stderr": "",
>> > "stdout": "11.11.4.74" # I need this entry in
>> > myhosts
>> > },
>> > {
>> > "changed": true,
>> > "cmd": "echo \"11.11.4.138\"",
>> > "delta": "0:00:00.001896",
>> > "end": "2014-08-25 22:28:46.227298",
>> > "invocation": {
>> > "module_args": "echo \"11.11.4.138\"",
>> > "module_name": "shell"
>> > },
>> > "item": "138",
>> > "rc": 0,
>> > "start": "2014-08-25 22:28:46.225402",
>> > "stderr": "",
>> > "stdout": "11.11.4.138" # I need this entry in
>> > myhosts
>> > }
>> > ]
>> > }
>> > }
>> >
>> > Note: Array size can change, this is just a sample output
>> >
>> > --
>> > 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 [email protected].
>> > To post to this group, send email to [email protected].
>> > To view this discussion on the web visit
>> >
>> > https://groups.google.com/d/msgid/ansible-project/c7d2179e-1ccf-4fea-9d65-0d685a6b02a5%40googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> -----------------------
>> | Henry Finucane
>> | "I hear aphorisms are popular"
>> -----------------------
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a033fe08-57b9-4882-bc6f-b3b26b807b73%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
-----------------------
| Henry Finucane
| "I hear aphorisms are popular"
-----------------------
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAGYSzJ8PyOXV5Bk%3Dcznyxf76qH8mXUdvkwu4GTgn5MpwaTeNVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.