ansible:如何更改$HOME目录

ansible:如何更改$HOME目录,ansible,Ansible,我正在我的控制机器ubuntu18.04桌面上运行ansible 2.9.6 控制单个服务器ubuntu16.04服务器,该服务器没有/home/username/目录。 我也不打算创造一个 我只是想从控制机器在从属机器中创建一个新文件夹“/usr/local/src/fromcontrolmachine” 所以我在命令下跑 dinesh@dinesh-VirtualBox:/etc/ansible$ ansible all -u dira --become -m file -a "dest

我正在我的控制机器
ubuntu18.04桌面上运行
ansible 2.9.6
控制单个服务器
ubuntu16.04
服务器,该服务器没有
/home/username/
目录。 我也不打算创造一个

我只是想从控制机器在从属机器中创建一个新文件夹“/usr/local/src/fromcontrolmachine”

所以我在命令下跑

 dinesh@dinesh-VirtualBox:/etc/ansible$ ansible all -u dira
 --become -m file -a "dest=/usr/local/src/fromcontrolmachine mode=755 owner=dira group=dira state=directory" -K 
成为密码:

我想通过在下面的行中添加来更改$Home目录 /etc/ansible/ansible.cfg。它刚刚创建了一个名为
ansible

 remote_tmp = usr/local/src/ansible
如何告诉ansible通过指向默认
/Home/dira
以外的其他位置来更改默认
$Home
目录

我想清除这个恼人的错误 “module_stdout”:“无法chdir到主目录/home/dira271641:没有这样的文件或目录。”

更新:

还尝试创建playbook
pb.yml
&添加
home\u dir:/usr/local/src/ansible
,如下所述

---

- hosts: all
  become: true
  tasks:
    - set_fact:
        home_dir: /usr/local/src/ansible
      become: true
    - name: ansible create directory example
      file:
        path: /tmp/devops_directory
        state: directory
当我在上面使用命令
ansible playbook pb.yml-K运行时

但它给出了与上述相同的错误

更新: 我尝试了
environment:HOME:

---
- hosts: all
  become: true
  environment: 
    HOME: /usr/local/src/ansible
  tasks:
  - name: ansible create directory example
    file:
      path: /tmp/devops_directory
      state: directory
抛出相同的错误

Could not chdir to home directory /home/dira: No such file or directory\r\n\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: setup\n"}
在第行下面添加

become_user: dira
已解决此问题。注意:dira是我的用户名。请替换您的用户名。 所以完整的剧本脚本看起来像

---
- hosts: all
  become: true
  become_user: dira
  environment: 
    HOME: /usr/local/src/ansible
  tasks:
  - name: ansible create directory example
    file:
      path: /tmp/devops_directory
      state: directory
---
- hosts: all
  become: true
  become_user: dira
  environment: 
    HOME: /usr/local/src/ansible
  tasks:
  - name: ansible create directory example
    file:
      path: /tmp/devops_directory
      state: directory