组节点上的ansible循环with_items并避免ssh

时间:2019-12-13 22:35:37

标签: ansible ansible-2.x ansible-inventory ansible-facts

团队,我在下面的任务中想在kubectl命令中使用节点名称,但是ansible正在对这些节点执行ssh。我不希望ssh发生在哪里,因为kubectl命令将在本地而不是在主机上运行。如何修改任务,使其仅使用其kubeclt命令中的节点名称?

 print(message_elements[0], message_elements[1], ...)

输出:

        shell: kubectl get node {{ item }} -o json
        ignore_errors: no
        register: node_info
        failed_when: node_info.rc == 0
        delegate_to: "{{ item }}"
        with_items: "{{ groups['kube-gpu-node'] }}"
      - debug:
          var: node_info

预期输出:样品..

TASK [: Alternate to K8s_facts use Command] ****************************************************************************************************************************
failed: [localhost] (item=node2) => {"ansible_loop_var": "item", "item": "node2", "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname node2.team.try.com.net: Name or service not known", "unreachable": true}
failed: [localhost] (item=node1) => {"ansible_loop_var": "item", "item": "node1", "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname node1.team.try.com.net: Name or service not known", "unreachable": true}
fatal: [localhost]: UNREACHABLE! => {"changed": false, "msg": "All items completed", "results": [{"ansible_loop_var": "item", "item": "node2", "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname node2.team.try.com.net: Name or service not known", "unreachable": true}, {"ansible_loop_var": "item", "item": "node1", "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname node1.team.try.com.net: Name or service not known", "unreachable": true}]}

1 个答案:

答案 0 :(得分:0)

弄清楚:我不应该使用委托_来

        shell: kubectl get node {{ item }} -o json
        ignore_errors: no
        register: node_info
        failed_when: node_info.rc != 0
        with_items: "{{ groups['kube-gpu-node'] }}"
      - debug:
          var: node_info