LoginSignup
1
1

More than 5 years have passed since last update.

Ansibleで「~/」を指定した際に指し示す場所

Last updated at Posted at 2016-08-11

結論から言うと、become: yesを付けた時点で「~/」は「/root」を指し示した。
becomebecome_methodbecome_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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1