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.

Reply via email to