I have a task, that creates a group.
- name: add user to docker group user: name=USERNAME groups=docker append=yes sudo: true
In another playbook I need to run a command that relies on having the new group permission. Unfortunately this does not work because the new group is only loaded after I logout and login again.
I have tried some stuff like:
su -l USERNAME
or
newgrp docker; newgrp
But nothing worked. Is there any change to force Ansible to reconnect to the host and does a relogin? A reboot would be the last option.
Is it a bug? A reboot is not required to add a user to a group.
To update group membership and apply the assigned permissions or Group Policies, you need to restart the computer (if a computer account was added to the domain group) or perform a logoff and logon (for the user).
You can use an (ansible.builtin.
)meta: reset_connection
task:
- name: add user to docker group ansible.builtin.user: name: USERNAME groups: docker append: yes - name: reset ssh connection to allow user changes to affect ansible user ansible.builtin.meta: reset_connection
Note that you can not use a variable to only run the task when the ansible.builtin.user
task did a change as “reset_connection
task does not support when
conditional”, see #27565.
The reset_connection
meta task was added in Ansible 2.3, but remained a bit buggy until excluding v2.5.8, see #27520.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With