Restart SSH connection during play

Hello,

I have a task in a play that appends a group to the user running the playbook. For example, ubuntu user is running the play and does a task like:

  • name: Append user group
    sudo: yes
    user:
    name=“ubuntu”
    append=“yes”
    groups=“othergroup”

A later task then assumes that the ubuntu user can write to directories with othergroup write access. This is fine if ansible is not running with ControlMaster enabled since it starts a new SSH connection for every task. It is a problem when ControlMaster is enabled though because it re-uses the same connection which doesn’t cause the remote SSH process to re-load the user groups (meaning the process cannot write to the directory as expected).

In the past (using fabric) I could force the SSH connection to close after this task, but I don’t see a way to do that in ansible (which is probably better since that’s a hack). Is there a good way to reload the user’s group?

Thanks!