Ansible delegate_to尝试ssh的任务

时间:2017-07-11 13:20:44

标签: ansible ansible-inventory

我有一个简单的安全角色和这个角色中的几个基本任务。所有任务都定义为local_action(或delegate_to: localhost)。剧本中定义的主持人也是localhost

现在,当我运行这个剧本时,它首先尝试在执行角色/任务之前测试ssh连接。这不是问题,但我发现在运行明确以localhost为主机的Playbook之前,无需建立或测试ssh连接。以下是我的剧本(playbook.yml)的样子:

- hosts: db-servers
  roles:
  - role: test

角色定义(roles/test/tasks/main.yml)如下所示:

---
  - name: Resolve and copy test configuration
    template:
      src: "roles/test/templates/temp.conf"
      dest: "roles/test/files/temp-4.2.0/temp.conf"
    delegate_to: 127.0.0.1
    become: no

  - name: Run test job
    delegate_to: 127.0.0.1
    command: roles/test/files/test-4.2.0/test.sh
    become: no

以下是我的广告资源文件inv/test

[db-servers]
localhost

我正在使用此命令来运行我的剧本:

ansible-playbook -i inv/test playbook.yml -vvv

无论如何,我可以阻止这种ssh连接检查吗?

1 个答案:

答案 0 :(得分:3)

connection: local添加为任务属性。

- name: Run test job
  delegate_to: 127.0.0.1
  connection: local
  command: roles/test/files/test-4.2.0/test.sh
  become: no

或者在清单中定义主机并分配连接类型:

127.0.0.1 ansible_connection=local