Hi,

I'm trying out (Ansible 2.0.2.0 on Fedora 23). The snippet below is also on http://pastie.org/10821272

Goal: expand task #3 below so it installs for existing users all the files listed in the variable mc_templates.

Question: I tinkered but couldn't make it work (snippet + error at the end) so how do I do that? Is with_nested the right one to use? How do I reference items in user_exists.results and mc_templates?

vars:
mc_users:
     - usr: patrick
       base: /home/
     - usr: root
       base: /
     - usr: mockbuild
       base: /home/

mc_templates:
     - src: mc/ini.j2
       dst: ini

tasks:

- name: mc-set-colors | task #1 check if user exists
shell: /usr/bin/getent passwd {{ item.usr }} | /usr/bin/wc -l | tr -d ' '
    with_items:
      - "{{ mc_users }}"
    register: "user_exists"
    tags: mc-set-colors

- name: mc-set-colors | task #2 make sure mc config dir exists
    file:
      dest: "{{ item.item.base }}{{ item.item.usr }}/.config/mc"
      owner: "{{ item.item.usr }}"
      group: "{{ item.item.usr }}"
      mode: 0755
      state: directory
      recurse: yes
    with_items:
      - "{{ user_exists.results }}"
    when: item.stdout == "1"
    tags: mc-set-colors

- name: mc-set-colors | task #3 install mc config template
    template:
      src: "mc/ini.j2"
      dest: "{{ item.item.base }}{{ item.item.usr }}/.config/mc/ini"
      owner: "{{ item.item.usr }}"
      group: "{{ item.item.usr }}"
      mode: 0644
      force: yes
      backup: no
    with_items:
      - "{{ user_exists.results }}"
    when: item.stdout == "1"
    tags: mc-set-colors

^^^ task #1, #2 and #3 work fine. I tried the change task #3 below but that results in an error. Any ideas?

- name: mc-set-colors | install mc config template
   template:
     src: "{{ item.1.src }}"
dest: "{{ item.item.base }}{{ item.item.usr }}/.config/mc/{{ item.1.dst }}"
     owner: "{{ item.item.usr }}"
     group: "{{ item.item.usr }}"
     mode: 0644
     force: yes
     backup: no
   with_nested:
     - "{{ user_exists.results }}"
     - "{{ mc_templates }}"
   when: item.stdout == "1"
   tags: mc-set-colors


Resulting error:

TASK [laptop : mc-set-colors | install mc config template] ********************* fatal: [laptop]: FAILED! => {"failed": true, "msg": "'list object' has no attribute 'item'"}


Thanks for any pointers.

Cheers,
Patrick

--
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/8b1d463f-8ba6-62d1-686e-dc652d09c75a%40laimbock.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to