首页 > 解决方案 > 我们可以在 ansible playbook 中设置 remote_tmp 值吗

问题描述

我想为每个剧本在 ansible 中设置不同的 remote_tmp 变量值。是否可以在剧本中定义这个变量值?

标签: ansible

解决方案


问: “我们可以在 ansible playbook 中设置 remote_tmp 值吗?”

答:是的。您可以设置ansible_remote_tmp。例如,下面的剧本使用默认值~/.ansible/tmp

shell> cat playbook.yml
- hosts: test_01
  tasks:
    - debug:
        var: ansible_remote_tmp
    - shell: uname -a

shell> ansible-playbook playbook.yml -vvv

TASK [debug] ****
task path: /export/scratch/tmp/playbook.yml:3
ok: [test_01] => 
  ansible_remote_tmp: 'VARIABLE IS NOT DEFINED!:
                      ''ansible_remote_tmp'' is undefined'

TASK [shell] ****
task path: /export/scratch/tmp/playbook.yml:5
<test_01> ESTABLISH SSH CONNECTION FOR USER: admin
... echo /home/admin/.ansible/tmp/ansible-tmp-1599833593. ...

在下面的剧本中,远程 tmp 设置为/tmp

shell> cat playbook.yml
- hosts: test_01
  vars:
    ansible_remote_tmp: /tmp
  tasks:
    - debug:
        var: ansible_remote_tmp
    - shell: uname -a

shell> ansible-playbook playbook.yml -vvv

TASK [debug] ****
task path: /export/scratch/tmp/playbook.yml:11
ok: [test_01] => 
  ansible_remote_tmp: /tmp

TASK [shell] ****
task path: /export/scratch/tmp/playbook.yml:13
<test_01> ESTABLISH SSH CONNECTION FOR USER: admin
... echo /tmp/ansible-tmp-1599833597. ...


推荐阅读