title: Ansible create Users and Group
body: <p>I am trying to create new users and groups using Ansible playbook. Below is my folder structure.</p>
  
  <pre><code>tree
  .
  ├── create-users.yaml
  └── ubuntu
  </code></pre>
  
  <p><code>create-users.yaml</code> playbook contains create user and group tasks. Note, I am not having any group (admin_group) and users (Rajini, Kamal) in my target machine, instead they will be created when running the playbook.</p>
  
  <pre><code>---
  - name:  Create Users &amp; Groups
    hosts: target1
    gather_facts: false
    tasks:
      - name: Create Users Task
        user:
          name: "{{ item }}"
          state: present
          password: "{{ 'default_user_password' | password_hash('sha512','A512') }}"
          shell: /bin/bash
          groups: "{{ admin_group }}"
        loop:
          - Rajini
          - Kamal
  </code></pre>
  
  <p>I have another file called <code>ubuntu</code> to pick group name and password. When running the playbook I am getting below error.</p>
  
  <pre><code>ansible-playbook --vault-id @prompt create-users.yaml -K
  BECOME password:
  Vault password (default):
  
  PLAY [Create Users &amp; Groups] *****************************************************************************************************************************************************************
  
  TASK [Create Users Task] *********************************************************************************************************************************************************************
  fatal: [target1]: FAILED! =&gt; {"msg": "The task includes an option with an undefined variable. The error was: 'admin_group' is undefined\n\nThe error appears to be in '/home/osboxes/Ansible_Project/web_deployment/Ansible/groups_vars/create-users.yaml': line 6, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n    - name: Create Users Task\n      ^ here\n"}
  
  PLAY RECAP ***********************************************************************************************************************************************************************************
  target1                    : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
  
  </code></pre>
  
  <pre><code>admin_group: admin
  default_user_password: Password1
  </code></pre>
  
  <p>Can somebody please help me on this?</p>
  
  <p>Updating Output after getting help from user Moon.</p>
  
  <pre><code>ansible-playbook --vault-id @prompt create-users.yaml -K
  BECOME password:
  Vault password (default):
  
  PLAY [Create Users &amp; Groups] *****************************************************************************************************************************************************************
  
  TASK [Create Users Task] *********************************************************************************************************************************************************************
  changed: [target1] =&gt; (item=Rajini)
  changed: [target1] =&gt; (item=Kamal)
  
  PLAY RECAP ***********************************************************************************************************************************************************************************
  target1                    : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
  
  </code></pre>
  
  <pre><code>ssh Kamal@192.168.0.1
  Kamal@192.168.0.1's password:
  Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 5.0.0-23-generic x86_64)
  Kamal@Ansible_Target1:~$ id
  uid=1005(Kamal) gid=1001(admin) groups=1001(admin)
  </code></pre>