結論から言うと、become: yes
を付けた時点で「~/」は「/root」を指し示した。
become
、become_method
、become_user
の組み合わせで「~/」の指定ユーザに変更することは可能。
playbookのコメントでファイルが作成された位置を追記しています。
実験のplaybookの内容
ansible-playbook -i hosts_vagrant playbook_test20160811.yml --tags debug数字
で実験した
- hosts: targets
tasks:
# /home/vagrant/20160811
- name: "debug1"
file:
path: "~/20160811"
state: touch
tags:
- debug1
# /root/20160811
- name: "debug2"
become: yes
file:
path: "~/20160811"
state: touch
tags:
- debug2
# /home/vagrant/20160811
- name: "debug3"
shell: /bin/bash -lc "touch ~/20160811"
tags:
- debug3
# /root/20160811
- name: "debug4"
become: yes
shell: /bin/bash -lc "touch ~/20160811"
tags:
- debug4
# /home/vagrant/20160811
- name: "debug5"
shell: /bin/bash -lc "touch 20160811"
args:
chdir: "~"
tags:
- debug5
# /root/20160811
- name: "debug6"
become: yes
shell: /bin/bash -lc "touch 20160811"
args:
chdir: "~"
tags:
- debug6
# /home/vagrant/20160811
- name: "debug7"
become: yes
become_user: "vagrant"
become_method: su
shell: /bin/bash -lc "touch ~/20160811"
tags:
- debug7
# /home/vagrant/20160811
- name: "debug8"
become: yes
become_user: "vagrant"
become_method: su
shell: /bin/bash -lc "touch 20160811"
args:
chdir: "~"
tags:
- debug8