Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Reselvendo erros de Permission denied (publickey,password) e [WARNING]: No inventory was parsed, only implicit localhost is available

Colegas, Boa Tarde!

Depois de encontrar problemas em rodar o "Hello World!" e, não ter encontrado especificamente uma solução, resolvi postar aqui o que talvez possa ajudar

1) Erro da private_key: Permission denied (publickey,password)

Comando:

 ansible wordpress -u vagrant -i hosts --private-key /vagrant/.vagrant/machines/wordpress/virtualbox/private_key -m shell -a 'echo Hello, World!'

Display do erro:

192.168.0.27 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n@ WARNING: UNPROTECTED PRIVATE KEY FILE! @\r\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\nPermissions 0777 for '/vagrant/.vagrant/machines/wordpress/virtualbox/private_key' are too open.\r\nIt is required that your private key files are NOT accessible by others.\r\nThis private key will be ignored.\r\nLoad key "/vagrant/.vagrant/machines/wordpress/virtualbox/private_key": bad permissions\r\nvagrant@192.168.0.27: Permission denied (publickey,password).", "unreachable": true }

Solução: Esse erro ocorreu, porque o vagrant (onde criei minha máquina ansible) cria a private_key com permissão total (777). copiei a chave para o diretório .ssh e fiz chmod 600.

2) [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

Comando:

ansible wordpress -u vagrant --private-key /home/vagrant/.ssh/private_key -i hosts -m shell -a 'echo Hello, World!'

Display do erro:

[WARNING]: Unable to parse /home/vagrant/.ssh/hosts as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

[WARNING]: Could not match supplied host pattern, ignoring: wordpress

Solução: O ansible utiliza com o default o diretório /etc/ansible/hosts (trecho do arquivo ansible.cfg):

root@ubuntu-bionic:/etc/ansible# cat ansible.cfg

config file for ansible -- https://ansible.com/

===============================================

nearly all parameters can be overridden in ansible-playbook

or with command line flags. ansible will read ANSIBLE_CONFIG,

ansible.cfg in the current working directory, .ansible.cfg in

the home directory or /etc/ansible/ansible.cfg, whichever it

finds first

[defaults]

some basic default values...

#inventory = /etc/ansible/hosts

A solução, foi informar o caminho completo do meu hosts "-i -i /vagrant/hosts:

vagrant@ubuntu-bionic:/vagrant$ ansible wordpress -u vagrant --private-key /home/vagrant/.ssh/private_key -i /vagrant/hosts -m shell -a 'echo Hello, World!'
192.168.0.27 | CHANGED | rc=0 >>
Hello, World!

Desejo ter contribuído com alguém que possa ter encontrado a mesma dificuldade.

Abraço e Bons Estudos a todos!!

1 resposta
solução!

Olá Alex, tudo bem? Que legal sua contribuição, muito bom mesmo, vai ajudar muitos outros colegas com certeza. Continue assim e bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software