Oba*_*oof 4 ansible ansible-inventory
我在这个角色中有一个简单的 ansible 角色和几个基本任务。所有任务都定义为local_action(或delegate_to: localhost)。剧本中定义的主机也是localhost.
现在,当我运行这个剧本时,它首先尝试在执行角色/任务之前测试 ssh 连接。这不是问题,但我发现在运行明确定位localhost为主机的 playbook 之前没有必要建立或测试 ssh 连接。以下是我的剧本 ( playbook.yml) 的样子:
- hosts: db-servers
roles:
- role: test
Run Code Online (Sandbox Code Playgroud)
角色定义 ( 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
Run Code Online (Sandbox Code Playgroud)
以下是我的库存文件inv/test:
[db-servers]
localhost
Run Code Online (Sandbox Code Playgroud)
我正在使用这个命令来运行我的剧本:
ansible-playbook -i inv/test playbook.yml -vvv
Run Code Online (Sandbox Code Playgroud)
无论如何,我是否可以阻止此 ssh 连接检查?
添加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
Run Code Online (Sandbox Code Playgroud)
或者在清单中定义主机并分配连接类型:
127.0.0.1 ansible_connection=local
Run Code Online (Sandbox Code Playgroud)