On 01/09/16 14:10, appeltabak wrote:
Hi,

Currently, I'm transforming my user role from creating one user to creating multiple users. In many examples I've seen this is done by adding with_items to every tasks related to the creation of the user (create user, add authorized key, etc). This would result in executing every tasks for every listed user before moving to the next tasks (right?) But what I want is that the whole task fileis run from top to bottom, for every listed user. /

/I've tried this approach: https://gist.github.com/Appeltabak/7f20f9f6e4fed80202cc2dd5d0044b5f Unfortunately, this gives an undefined variable error when the outer_users is used in subsequent tasks.
/
TL;DR How can I run a task file with //with_items/ ?
OK - so you define your user vars like this in vars/users.yml:

users:
  - name: User of apples
    user: apple
    uid: 500
    home: /home/apple
    shell: /bin/bash
  - name: Orange Guy
    user: orange
    uid: 501
    home: /home/orange
    shell: /bin/bash

Then a basic playbook would be:

---

- name: Users
  become: true
  hosts: hostlist
  vars_files:
    - vars/users.yml

  tasks:
  - name: Create new users
    user:
      createhome: yes
      home: "{{ item.home }}"
      comment: "{{ item.name }}"
      user: "{{ item.user }}"
      uid: "{{ item.uid }}"
      shell: "{{ item.shell }}"
    with_items: "{{ users }}"

Cheers

Iain


Thanks
--
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] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5c62db30-0ef4-4732-a545-726a501ca53f%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/5c62db30-0ef4-4732-a545-726a501ca53f%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
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/40e2d770-b731-2655-505a-800205713473%40shihad.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to