title: Choose entry from a list (creating users)
body: <p>First thing first - I'm not an Ansible wiz and I guess there is a better way to do this, but this is how I managed to do this. 
  I needed to create users on Linux servers, I used this to read the users parameters from a file and create all by using 'with_items'. </p>
  
  <p>This worked perfectly.</p>
  
  <p>I wanted to add an option to create only one user from the list. </p>
  
  <p>This is my yml script:</p>
  
  <pre><code>---
  - hosts: all
    user: deploy
    become: yes
  
    tasks:
    - include_vars: ../variables/users.yml
      #  - command: echo {{ Guser }}
    - debug: msg={{ users }}
  
    - name: Create DevOps team users
      user: name={{ item.username }} shell=/bin/bash createhome=yes comment='Created by Ansi' groups={{ item.use_sudo }} uid={{ item.use_uid }} group={{ item.use_group }} state=present
      ignore_errors: yes
      with_items:
        - '{{ Guser }}'
      when: Guser is defined
  </code></pre>
  
  <p>And this is how I run it: </p>
  
  <pre><code>ansible-playbook --extra-vars "Guser=gilil2" -l myserver /home/devops/roles/create-users/tasks/create_user_by_name.yml -u deploy
  </code></pre>
  
  <p>Snip from my variables/users.yml</p>
  
  <pre><code>---
  users:
    - username: gilil
      use_sudo:
      use_uid: 2005
      use_group: users
  
    - username: gilil2
      use_sudo:
      use_uid: 1010
      use_group: users
  
    - username: gilil3
      use_sudo:
      use_uid: 1011
      use_group: users
  </code></pre>