On Thu, 20 Jul 2017 18:49:55 -0700 (PDT)
Anfield <gareth.has...@gmail.com> wrote:

> What is the correct way to use with_Items to loop over two files? The 
> playbook is failing at the 2nd task
> 
> Getting an error - TASK [Create users from vars users] 
> ********************************************
> fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field
> 'args' has an invalid value, which appears to include a variable that
> is undefined. The error was:
> 'ansible.vars.unsafe_proxy.AnsibleUnsafeText object' has no attribute
> 'users'\n\nThe error appears to have been in
> '/etc/ansible/playbooks/exercises/usersgroups.yml': line 15, column
> 6, but may\nbe elsewhere in the file depending on the exact syntax
> problem.\n\nThe offending line appears to be:\n\n\n   - name: Create
> users from vars users\n     ^ here\n"}
> 
> users.yml (is below, grouplist.yml is similar)
> ---
> users:
> - jock
> - dejan
> - joel
> 
> Playbook is below -
> 
>     - users.yml
>     - grouplist.yml
>   tasks:
> 
>    - name: Create groups from vars file
>      group:
>         name: "{{item}}"
>         state: present
>      with_items: "{{grouplist}}"
> 
>    - name: Create users from vars users
>      user:
>         name: "{{item.users}}"
>         state: present
>         groups: "{{item.grouplist}}"
>      with_items:
>          - "{{ users}}"
>          - "{{grouplist}}"

Assuming that what you want to do is create a number of groups listed
in the grouplist variable, and then create the users listed in the
users variable, where each user is member of all groups in the
grouplist variable, your second task should be one of the following
(Ansible 2.3 can accept lists directly in "groups" attribute):

- name: Create users from vars users (Ansible 2.3+)
  user:
    name: "{{ item }}"
    state: present
    groups: "{{ grouplist }}"
  with_items: "{{ userlist }}"

- name: Create users from vars users (Ansible <2.3)
  user:
    name: "{{ item }}"
    state: present
    groups: "{{ grouplist | join(',') }}"
  with_items: "{{ userlist }}"

Best regards

-- 
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20170721143214.2f4a4ee0%40majic.rs.
For more options, visit https://groups.google.com/d/optout.

Reply via email to