On Mon, 30 Dec 2019 02:07:24 -0800 (PST)
Yehuda Pinhas <[email protected]> wrote:

> Can you please take a look on my errors and try to help me figuring out why 
> I am getting them?

Sure. As a working example, the playbook

  - hosts: localhost
    vars:
      
      my_hosts:
        - group: 'POC_ENV'
          hosts: "{{ lookup('file',
                     
'/home/ansible/MACCABI/hosts/POC-ENV_list.yml').splitlines() }}"
    tasks:
      - add_host:
          name: "{{ item.1 }}"
          groups: "{{ item.0.group }}"
          ansible_ssh_private_key_file: /home/ansible/.ssh/id_rsa
          ansible_ssh_common_args: -o StrictHostKeyChecking=no
                                   -o UserKnownHostsFile=/dev/null
          ansible_user: ansible
        loop: "{{ lookup('subelements', my_hosts, 'hosts') }}"

  - hosts: POC_ENV
    tasks:
      - debug:
          msg: "{{ msg.split('\n') }}"
        vars:
          msg: |
            host [{{ inventory_hostname }}]
            key [{{ ansible_ssh_private_key_file}}]
            args [{{ ansible_ssh_common_args }}]
            user [{{ ansible_user }}]

gives

ok: [POC_ENV_01] => {
    "msg": [
        "host [POC_ENV_01]", 
        "key [/home/ansible/.ssh/id_rsa]", 
        "args [-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null]", 
        "user [ansible]", 
        ""
    ]
}
ok: [POC_ENV_02] => {
    "msg": [
        "host [POC_ENV_02]", 
        "key [/home/ansible/.ssh/id_rsa]", 
        "args [-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null]", 
        "user [ansible]", 
        ""
    ]
}
ok: [POC_ENV_03] => {
    "msg": [
        "host [POC_ENV_03]", 
        "key [/home/ansible/.ssh/id_rsa]", 
        "args [-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null]", 
        "user [ansible]", 
        ""
    ]
}


Notes:

* In your code "hosts: POC-ENV" the name of the group is not valid.
* See "add_host" examples how to add variables to the inventory
  https://docs.ansible.com/ansible/latest/modules/add_host_module.html#examples
* Run "ansible-lint playbook.yml" before posting the code

HTH,

        -vlado

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20191230122617.399a78bd%40gmail.com.

Attachment: pgpDqj4M0wlOp.pgp
Description: OpenPGP digital signature

Reply via email to