I'm trying to create a gropu with Ansible, which fails but works if I run it as an SSH command.
The Play
- name: Test error creating groups
hosts: all
become: yes
become_method: sudo
become_user: xdradmin
tasks:
- name: Ensure test group exists
group:
name: test
state: present
gid: 1001
Attempting to create the group fails with error.
$ ansible-playbook -i web, -u xdradmin test.yml
PLAY [Test error creating groups] ********************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************
ok: [web]
TASK [Ensure test group exists] **********************************************************************************************
fatal: [web]: FAILED! => {"changed": false, "msg": "groupadd: Permission denied.\ngroupadd: cannot lock /etc/group; try again later.\n", "name": "test"}
PLAY RECAP *******************************************************************************************************************
web : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
However if I do essentially the same thing manually, it works fine.
ssh xdradmin@web 'sudo groupadd -g 1001 test && tail -n1 /etc/group'
test:x:1001: