首页 文章

Ansible delegate_to尝试ssh的任务

提问于
浏览
1

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

现在当我运行这个剧本时,它首先尝试在执行角色/任务之前测试ssh连接 . 这不是问题,但我发现在运行明确以 localhost 为主机的Playbook之前,没有必要 Build 或测试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连接检查?

1 回答

  • 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
    

相关问题