グループを作成するタスクがあります。
- name: add user to docker group
user: name=USERNAME groups=docker append=yes
sudo: true
別のプレイブックでは、新しいグループの権限を必要とするコマンドを実行する必要があります。残念ながら、新しいグループはログアウトして再度ログインした後にのみ読み込まれるため、これは機能しません。
私は次のようなことを試しました:
su -l USERNAME
または
newgrp docker; newgrp
しかし、何も機能しませんでした。Ansible を強制的にホストに再接続して再ログインさせる変更はありますか? 再起動が最後のオプションになります。
ベストアンサー1
あなたは(ansible.builtin.
)meta: reset_connection
タスク:
- name: Add user to docker group
ansible.builtin.user:
name: USERNAME
groups: docker
append: true
- name: Reset ssh connection to allow user changes to affect ansible user
ansible.builtin.meta:
reset_connection
以下の点に注意してくださいないタスクが条件付きをサポートしていないため、変数を使用してタスクがansible.builtin.user
変更された場合にのみタスクを実行します。reset_connection
when
#27565。
メタタスクreset_connection
はAnsible 2.3で追加されましたが、v2.5.8を除外するまで少しバグが残っていました。#27520。
reset_connection
タスク自体は条件をサポートしていませんがwhen
、次のように条件付きタスクの包含を使用できます。
- name: Add user to docker group
ansible.builtin.user:
name: USERNAME
groups: docker
append: true
register: add_to_docker_group_result
- name: Include reset connection tasks
ansible.builtin.include_tasks: reset_connection.yaml
when: add_to_docker_group_result.changed == true
reset_connection.yaml
含めるファイルは次のとおりです:
- name: Reset ssh connection
ansible.builtin.meta: reset_connection