Ansible Create Users and Groups - failed with no information

The task got failed without any information. Can you please check what went wrong?

Task Status - Failed
You may check your work again to see what went wrong. The environment expires in 5 minutes. If you think you did your work correctly and is marked failed, please take outputs/screenshot of your work and post in community.kodekloud.com.

something is strange with that task @Inderpreet @mmumshad can you check for us what’s wrong with it please ?

This issue is already resolved on another thread

1 Like

@rahul456
Ansible Create Users and Groups

Task Status - Failed
  • ‘rob’ user’s password is incorrect

You may check your work again to see what went wrong. The environment expires in 5 minutes. If you think you did your work correctly and is marked failed, please take outputs/screenshot of your work and post in community.kodekloud.com.

I have encrypted the password given in question and used the same in playbook but still task failed.
Kindly check on it.

hor@jump_host ~/playbooks$ ansible-vault encrypt_string ‘8FmzjvFU6S’ --vault-password-file=~/playbooks/secrets/vault.txt
!vault |
$ANSIBLE_VAULT;1.1;AES256
38343766663138366639393765386562323763313163306666636133386230633363656362393566
3463336133616562353064346663346166616433396631380a366535373963373762663936333764
33363530663863336432633138396134336564306532343132363862343738646639333831373765
3436326466313765310a343737363936343864356563656536636132616530396534353064383035
3632
Encryption successful
thor@jump_host ~/playbooks$ ansible-vault encrypt_string ‘LQfKeWWxWD’ --vault-password-file=~/playbooks/secrets/vault.txt
!vault |
$ANSIBLE_VAULT;1.1;AES256
61636131313337633865303366353135656364373762313334323535383133353838363934313534
3966646138643839376666623664616437323261376431380a656633326236353332313332376136
31633634366265656264383232633262643964666235303137383662663336336639366239626434
3338356330613536630a376634356238313266626361656234326563633765653462363366303231
3461
Encryption successful

  • name: user and group creation
    hosts: stapp03
    become: true
    vars_files:
    • ~/playbooks/data/users.yml
      vars:
      password: !vault |
      $ANSIBLE_VAULT;1.1;AES256
      38343766663138366639393765386562323763313163306666636133386230633363656362393566
      3463336133616562353064346663346166616433396631380a366535373963373762663936333764
      33363530663863336432633138396134336564306532343132363862343738646639333831373765
      3436326466313765310a343737363936343864356563656536636132616530396534353064383035
      3632
      password1: !vault |
      $ANSIBLE_VAULT;1.1;AES256
      61636131313337633865303366353135656364373762313334323535383133353838363934313534
      3966646138643839376666623664616437323261376431380a656633326236353332313332376136
      31633634366265656264383232633262643964666235303137383662663336336639366239626434
      3338356330613536630a376634356238313266626361656234326563633765653462363366303231
      3461
      tasks:
    • name: group creation
      group:
      name: “{{item}}”
      state: present
      with_items:
      • developers
      • admins
    • name: user creation
      user:
      name: “{{item}}”
      state: present
      groups: “admins, wheel”
      password: “{{ password1 }}”
      loop:
      “{{admins}}”
    • name: user creation
      user:
      name: “{{item}}”
      state: present
      groups: developers
      home: /var/www
      password: “{{ password }}”
      loop:
      “{{developers}}”
      thor@jump_host ~/playbooks$

thor@jump_host ~/playbooks$ cat ansible.cfg
[defaults]
host_key_checking = False
vault_password_file = ~/playbooks/secrets/vault.txt
thor@jump_host ~/playbooks$

I failed this tasks but it is no clear what was the error, my playbook ran fine and users and groups were added as indicated

Blockquotethor
@jump_host ~/playbooks$ ansible-playbook -i inventory add_users.yml --vault-password-file=~/playbooks/secrets/vault.txt

PLAY [stapp03] **************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************
ok: [stapp03]

TASK [Ensure group “admins” exists] *****************************************************************************
ok: [stapp03]

TASK [Ensure group “developers” exists] *************************************************************************
ok: [stapp03]

TASK [Add admins to “admins” group] *****************************************************************************
changed: [stapp03] => (item=rob)
changed: [stapp03] => (item=david)
changed: [stapp03] => (item=joy)

TASK [Add developers to “developers” group] *********************************************************************
changed: [stapp03] => (item=tim)
changed: [stapp03] => (item=ray)
changed: [stapp03] => (item=jim)
changed: [stapp03] => (item=mark)

PLAY RECAP ******************************************************************************************************
stapp03 : ok=5 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Blockquote

rob:x:1002:1004::/home/rob:/bin/bash
david:x:1003:1005::/home/david:/bin/bash
joy:x:1004:1006::/home/joy:/bin/bash
tim:x:1005:1007::/var/www/tim:/bin/bash
ray:x:1006:1008::/var/www/ray:/bin/bash
jim:x:1007:1009::/var/www/jim:/bin/bash
mark:x:1008:1010::/var/www/mark:/bin/bash

admins:x:1002:rob,david,joy
developers:x:1003:tim,ray,jim,mark

My Playbook

  • hosts: stapp03
    become: true
    remote_user: root
    vars_files:
    • data/users.yml
      vars:

    • admin_password: !vault |
      $ANSIBLE_VAULT;1.1;AES256
      62666535643561346436366137323564643961613337633630326338373339396639646231323335
      6534613662366338323134313333353464353161613838340a306364666365376165623232353231
      66383232663966316135386466623035363839343866363266363334623531663063656639343932
      3137343962343433650a333761303165353839393362303963626531666438313565393231343264
      3337

    • dev_password: !vault |
      $ANSIBLE_VAULT;1.1;AES256
      62666535643561346436366137323564643961613337633630326338373339396639646231323335
      6534613662366338323134313333353464353161613838340a306364666365376165623232353231
      66383232663966316135386466623035363839343866363266363334623531663063656639343932
      3137343962343433650a333761303165353839393362303963626531666438313565393231343264
      3337
      tasks:

    • name: Ensure group “admins” exists
      ansible.builtin.group:
      name: admins
      state: present

    • name: Ensure group “developers” exists
      ansible.builtin.group:
      name: developers
      state: present

    • name: Add admins to “admins” group
      ansible.builtin.user:
      name: “{{ item }}”
      password: “{{ admin_password | string |password_hash (‘sha512’) }}”
      createhome: yes
      shell: /bin/bash
      groups: admins,wheel
      append: yes
      loop: “{{ admins }}”

    • name: Add developers to “developers” group
      ansible.builtin.user:
      name: “{{ item }}”
      password: “{{ dev_password | string | password_hash (‘sha512’) }}”
      createhome: yes
      home: “/var/www/{{ item }}”
      shell: /bin/bash
      groups: developers
      append: yes
      loop: “{{ developers }}”

Same issue here ,

This task is always failing . Please help . This is how I did . All users were created under their respective groups , still it failed
Command to encrypt the password :
ansible-vault encrypt_string BruCStnMT5 : Developer
ansible-vault encrypt_string YchZHRcLkL : Admin
Playbook:

hosts: stapp02
become: yes
gather_facts: no
vars:
admin_pass: !vault |
$ANSIBLE_VAULT;1.1;AES256
31303937316339393534663439643931653133353061313134313238646531663330353636643136
3135623931666662643332396363646437646462616432640a333234623237663032666231663135
34393561613438626530373837626563373336383264306366366337376436393939363265323436
3265636134353139310a343036636137343535346636323137306135346130633135383162663031
3339
developer_pass: !vault |
$ANSIBLE_VAULT;1.1;AES256
39386462303030626631333965656261323834376465636536363934373836643266366536353665
3162623831326563383538646138306634313232303536620a316364646530393366643537363162
33393666396461383734623364626365333763323335316566616138386163333833383838666661
3535643336333834300a333164626165363635653364656537666534343830366366353964616436
3036
tasks:

    name: create groups
    group:
    name: “{{ item }}”
    state: present
    with_items:
        admins
        developers

    name: Include user.yml
    include_vars:
    file: data/users.yml

    name: Creating admins
    user:
    name: “{{ item }}”
    password: “{{ admin_pass | string | password_hash(‘sha512’) }}”
    groups: wheel,admins
    with_items: “{{ admins | list }}”

    name: creating developers
    user:
    name: “{{ item }}”
    password: “{{ developer_pass | string | password_hash(‘sha512’) }}”
    home: /var/www
    groups: developers
1 Like

It’s fixed now . Had to add “vault_password_file” in ansible.cfg