I would like to output about how to use SSH password authentication when executing ansible.
(venv) [root@tspdev01 test_role]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
(venv) [root@tspdev01 test_role]#
-** Ansible version **
(venv) [root@tspdev01 test_role]# ansible --version
ansible 2.9.10
  config file = /root/.ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /root/venv/lib/python2.7/site-packages/ansible
  executable location = /root/venv/bin/ansible
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
(venv) [root@tspdev01 test_role]#
Added the following contents to ʻansible.cfg`
Additional content
[defaults]
ask_pass = True
ansible.cfg
/etc/ansible/ansible.cfg
It looks like this.
Execution result
(venv) [root@tspdev01 test_role]# ansible -i inventory/test01_inventory.ini test_servers -m ping --ask-pass
SSH password:
192.168.56.51 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
(venv) [root@tspdev01 test_role]#
→ If it is pong, ping communication is possible.
When I ran ansible for the first time, the following error was displayed.
error
(venv) [root@tspdev01 test_role]# ansible -i inventory/test01_inventory.ini test_servers -m ping
192.168.56.51 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).",
    "unreachable": true
}
(venv) [root@tspdev01 test_role]#
In the process of finding the cause of the error, I came up with the information "How to use SSH password authentication when running ansible".
[UNREACHABLE! Failed to connect to the host via ssh: Permission denied error and cannot log in to the target host](https://curecode.jp/tech/ansible-unreachable-failed-to-connect-to-the-host -via-ssh-permission-denied /)
Recommended Posts