Ansible become関連設定のサンプル
機能
become: true
Ansible がリモートホストで処理を実行するとき、通常はログインユーザーの権限でコマンドを実行します。
become: true を指定すると、sudo などを使って root または別のユーザーに昇格してコマンドを実行します。
権限昇格を使う(true/false)
使用例1
Playbook 全体で指定する
実装コード
- name: Install package as root hosts: all become: true tasks: - name: Install nginx apt: name: nginx state: present
使用例2
タスクごとに指定も可能
- name: Create a file as root file: path: /root/hello.txt state: touch become: true