[LINUX] [Ansible] How to use SSH password authentication when executing ansible

Introduction

I would like to output about how to use SSH password authentication when executing ansible.

This environment

(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]#

Correspondence contents

Added the following contents to ʻansible.cfg`

Additional content


[defaults]
ask_pass = True

* The location of ʻansible.cfg` depends on the installation method. When installed with `yum install ansible`, it exists in the following directory.

ansible.cfg


/etc/ansible/ansible.cfg

Ping communication is carried out as a trial

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.

Background of this time

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".

reference

[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

[Ansible] How to use SSH password authentication when executing ansible
How to use fingerprint authentication for KDE
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use Seaboan
How to use image-match
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use pytest_report_header
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use x-means
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use Pyenv
How to use list []
How to use python-kabusapi
How to use OptParse
How to use return
How to use dotenv
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
Memo of how to use properly when combining pandas.DataFrame
Stop SSH password authentication and switch to key authentication completely
How to use Qt Designer
How to use search sorted
[gensim] How to use Doc2Vec
python3: How to use bottle (2)
Understand how to use django-filter
How to use the generator
[Python] How to use list 1
How to use FastAPI ③ OpenAPI
How to use Python argparse
How to use IPython Notebook
How to use Pandas Rolling
[Note] How to use virtualenv
How to use redis-py Dictionaries
Python: How to use pydub
[Python] How to use checkio
[Go] How to use "... (3 periods)"
How to use Django's GeoIp2
[Python] How to use input ()
How to use the decorator
[Introduction] How to use open3d
How to use Python lambda
How to use Jupyter Notebook
[Python] How to use virtualenv
python3: How to use bottle (3)