geerlingguy / ansible-role-docker

Ansible Role - Docker
https://galaxy.ansible.com/geerlingguy/docker/
MIT License
1.84k stars 857 forks source link

reset ssh connection to allow user changes to affect current login user #370

Closed fardke closed 2 years ago

fardke commented 2 years ago

Linked issues:

Why:

Without this modification, we can't use docker in same playbook than the one which install docker (in the case of we use docker_users variable).

How:

Check that docker_users are set and not in docker group before include docker-users.yml. In docker-users.yml we call reset_connectionfrom [ansible.builtin.meta](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/meta_module.html) collection afterdocker_users` are added to docker group.

Manual success tests:

geerlingguy commented 2 years ago

I had tried using that meta trick before but never could get it to pick things up in a playbook run over SSH correctly... maybe it was a bug in Ansible that's fixed now?

fardke commented 2 years ago

Hello, I never try to use meta reset_connection before, but on ansible core 2.13.3 it works directly. Some issues are closed on ansible related to this :

Two issues seems to be fixed.

geerlingguy commented 2 years ago

Heh, I even wrote an article on this: https://www.jeffgeerling.com/blog/2021/allowing-ansible-playbooks-work-new-user-groups-on-first-run