Ansible 任务在服务器上远程本地运行

时间:2021-01-11 19:59:17

标签: ansible

我正在尝试在我的 3 个服务器上创建空文件 /tmp/myfile。这是我的hosts/inventory.yml

all:
  hosts:
    DevMs1:
      ansible_host: 1.2.3.4
    DevMs2:
      ansible_host: 1.2.3.5
    DevMs3:
      ansible_host: 1.2.3.6

这是我的playbook.yml

---
- hosts: all
  tasks:
  - name: Create file
    command: touch /tmp/myfile
    args:
      creates: /tmp/myfile

问题是,该文件是在本地创建的,而不是在我的 3 个服务器上远程创建的。甚至 ping 成功:

$ ansible -i hosts/inventory.yaml all -m ping
DevMs2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
DevMs3 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
DevMs1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

据我所知,它正在 ping 本地主机。

我做错了什么,这种行为背后的逻辑是什么?我是 ansible 的新手,所以也许我遗漏了一些东西。

我可以通过 ssh 从本地主机访问服务器,没有任何问题。

0 个答案:

没有答案