Hi all,

I am trying to peform a series of tasks using with_items at task level.

I would like to see the tasks executed using different sudo users, so that 
I define at task level "become_user". 

As an example, this is my setup:

 roles/test/vars/main.yml

user_info:   
  - name: ubuntu
  - name: vagrant

roles/test/tasks/main.yml

- debug: msg="{{item}}"
  become_user: "{{ item.name }}"
  with_items: user_info

- name: test
  become_user: "{{ item.name }}"
  become: yes
  command: mkdir ~/testdir
  when: item.get('state', 'present') == 'present'
  with_items: user_info

playbooks/labs.yml

- name: Deploy Common Configuration

  hosts: deploy

  gather_facts: false


  roles:

  - { role: test }


Unfortunately, this does not work.


The debug task receive correctly the two items of the user_info variable :


ok: [fisher] => (item={u'name': u'ubuntu'}) => {

    "item": {

        "name": "ubuntu"

    }, 

    "msg": {

        "name": "ubuntu"

    }

}

ok: [fisher] => (item={u'name': u'vagrant'}) => {

    "item": {

        "name": "vagrant"

    }, 

    "msg": {

        "name": "vagrant"

    }

}

But unfortunately, the task "test" is run two times using only the first 
item as become_user

failed: [fisher] => (item={u'name': u'ubuntu'}) => {"changed": true, "cmd": 
["mkdir", "~/testdir"], "delta": "0:00:00.002188", "end": "2015-08-25 
15:14:26.175761", "failed": true, "item": {"name": "ubuntu"}, "rc": 1, 
"start": "2015-08-25 15:14:26.173573", "stderr": "mkdir: cannot create 
directory *'/home/ubuntu/testdir': File exists",* "stdout": "", 
"stdout_lines": [], "warnings": ["Consider using file module with 
state=directory rather than running mkdir"]}
 [WARNING]: Consider using file module with state=directory rather than 
running mkdir

failed: [fisher] => (item={u'name': u'vagrant'}) => {"changed": true, 
"cmd": ["mkdir", "~/testdir"], "delta": "0:00:00.002270", "end": 
"2015-08-25 15:14:26.436281", "failed": true, "item": {"name": "vagrant"}, 
"rc": 1, "start": "2015-08-25 15:14:26.434011", "stderr": "mkdir: cannot 
create directory *'/home/ubuntu/testdir': File exists",* "stdout": "", 
"stdout_lines": [], "warnings": ["Consider using file module with 
state=directory rather than running mkdir"]}

Is it normal behaviour ?

I a currently running on Ansible 2.0 devel version... commit:  



-- 
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/5e8d5b2a-da75-48c0-9dc8-764e9b620d9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to