Hi,
I’m new to Ansibel and i have been following “Learn Linux TV” youtube channel and his Ansibel episodes.
My problem is that i lose the connection when i run commands without specify the path to ¨/.ssj/ansibel and inventory.
Error description
It works to ping if i include my ssh file and inventory file:
ansible all --key-file ~/.ssh/ansible -i inventory -m ping
Then i created an ansible.cfg file and added inventory and private-key-file
ansible all -m ping
Both works.
The problem is that after a while, when i run the same command (ansible all -m ping
), i receive below error message:
ansible all -m ping
192.168.1.70 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: goran@192.168.1.70: Permission denied (publickey,password).”,
“unreachable”: true
}
192.168.1.72 | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: goran@192.168.1.72: Permission denied (publickey,password).”,
“unreachable”: true
}
I can solve this problem if i run ansible all --key-file ~/.ssh/ansible -i inventory -m ping
again.
After that i can run ansible all -m ping and other ansible commands (no path to ssh) with no errors.
It also works to run a playbook (but after a have run ansible all --key-file ~/.ssh/ansible -i inventory -m ping)
So it seems that i lost the path to my local ssh-file after a while.
I have search but not found why i lose the settings to ssh.
Does anyone know why i get this result and how to solve it?
Thanks in advance.
My settings
Debian GNU/Linux 11 (bullseye)|
Release: 11
Codename: bullseye
ansible [core 2.12.10]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/goran/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/goran/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
jinja version = 2.11.3
libyaml = True
ansible-playbook [core 2.12.10]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/goran/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /home/goran/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-playbook
python version = 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
jinja version = 2.11.3
libyaml = True
...
...
Ansibel project path:
/home/goran/git-projects/ansible/ansible_tutorial
**ansible.cfg**
defaults]
inventory = inventory
private-key-file =~ /.ssh/ansible
**inventory**
192.168.1.70
192.168.1.72
**install_apache.yml**
---
- name: Install Apache
hosts: all
become: true
tasks:
- name: Install Apache package
apt:
name: apache2
state: present
...