Ansible delegate_to 任务尝试 ssh

问题描述 投票:0回答:2

我有一个简单的 ansible 角色以及该角色中的几个基本任务。所有任务都定义为

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

ansible 中是否有可以阻止此 ssh 连接检查的方法?

ansible ansible-inventory
2个回答
12
投票

添加

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

0
投票

connection: local
旁边使用
delegate_to: 127.0.0.1
- 有效

© www.soinside.com 2019 - 2024. All rights reserved.