当 SSH 密钥连接失败时,如何告诉 Ansible 提示用户输入密码?

当 SSH 密钥连接失败时,如何告诉 Ansible 提示用户输入密码?

我与一支害怕 Linux 的网络工程师团队合作,我正在尝试为我的团队创造无缝的用户体验。

如何创建一个条件:当密钥认证失败时,提示用户输入用户名和密码?

这是我目前所拥有的:

---

- name: Get facts from core1.site1 Junos router
  hosts: routers
  connection: local
  gather_facts: no

  roles:
    - Juniper.junos
  vars_prompt:
    - name: netconf_user
      prompt: Username
      private: no
    - name: netconf_password
      prompt: Password
      private: yes
      register: results
  vars:
    default_port: 830
  tasks:
    - name: Get Junos Facts
      junos_get_facts:
        host: "{{ inventory_hostname }}"
     ######I would like the key authentication test to happen here, please.
        user: "{{ netconf_user }}"
        port: "{{ default_port }}"
        passwd: "{{ netconf_password }}"
      register: junos_facts_result
    - name: Print Junos Facts Result
      debug:
        var: junos_facts_result
    - name: Print Junos HOME Dir
      debug:
        var: junos_facts_result.facts.HOME
    - name: Print value of default_port
      debug:
        var: default_port

相关内容