6
respostas

Erro na public_key

TASK [Gathering Facts] *** fatal: [172.17.177.40]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: no such identity : seu caminho para chave/nome da chave privada: No such file or directory\r\nPermission denied (publickey,password).\r\n", "unreachable": true} to retry, use: --limit @/home/kalil/Ansible/teste/provisioning.retry

PLAY RECAP *** 172.17.177.40 : ok=0 changed=0 unreachable=1 failed=0

Como resolvo?

6 respostas

Depois foi esse

kalil@debian:~/Downloads/teste$ ansible-playbook -i hosts provisioning.yml

PLAY [all] ***************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************
fatal: [172.17.177.40]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to
host 172.17.177.40 port 22: Connection timed out\r\n", "unreachable": true}
        to retry, use: --limit @/home/kalil/Downloads/teste/provisioning.retry

PLAY RECAP ***************************************************************************************************************
172.17.177.40

Oi Kalil,

Vc consegue se conectar com o comando vagrant ssh?

Coloque aqui tbm o seu arquivo hosts, playbook e como vc chamou o ansible na linha de comando.

abs

Consigo subir a aplicação e entra via ssh

kalil@debian:~/Ansible/teste$ vagrant up
Bringing machine 'wordpress' up with 'virtualbox' provider...
==> wordpress: Importing base box 'ubuntu/trusty64'...
==> wordpress: Matching MAC address for NAT networking...
==> wordpress: Checking if box 'ubuntu/trusty64' is up to date...
==> wordpress: Setting the name of the VM: teste_wordpress_1546963372687_62796
==> wordpress: Clearing any previously set forwarded ports...
==> wordpress: Fixed port collision for 22 => 2222. Now on port 2200.
==> wordpress: Clearing any previously set network interfaces...
==> wordpress: Preparing network interfaces based on configuration...
    wordpress: Adapter 1: nat
    wordpress: Adapter 2: hostonly
==> wordpress: Forwarding ports...
    wordpress: 22 (guest) => 2200 (host) (adapter 1)
==> wordpress: Running 'pre-boot' VM customizations...
==> wordpress: Booting VM...
==> wordpress: Waiting for machine to boot. This may take a few minutes...
    wordpress: SSH address: 127.0.0.1:2200
    wordpress: SSH username: vagrant
    wordpress: SSH auth method: private key
    wordpress:
    wordpress: Vagrant insecure key detected. Vagrant will automatically replace
    wordpress: this with a newly generated keypair for better security.
    wordpress:
    wordpress: Inserting generated public key within guest...
    wordpress: Removing insecure key from the guest if it's present...
    wordpress: Key inserted! Disconnecting and reconnecting using new SSH key...
==> wordpress: Machine booted and ready!
==> wordpress: Checking for guest additions in VM...
    wordpress: The guest additions on this VM do not match the installed version of
    wordpress: VirtualBox! In most cases this is fine, but in rare cases it can
kalil@debian:~/Ansible/teste$ vagrant ssh
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-163-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Tue Jan  8 16:03:15 UTC 2019

  System load:  0.42              Processes:           82
  Usage of /:   3.6% of 39.34GB   Users logged in:     0
  Memory usage: 12%               IP address for eth0: 10.0.2.15
  Swap usage:   0%

  Graph this data and manage this system at:
    https://landscape.canonical.com/

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

New release '16.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


vagrant@vagrant-ubuntu-trusty-64:~$
`

/hosts/

[wordpress]
172.17.177.40 ansible_user=vagrant ansible_ssh_private_key_file="/home/kalil/Ansible/teste/.vagrant/machines/wordpress/virtualbox/private_key"

/provisioning/

---
- hosts: all
  handlers:
    - name: restart apache
      service:
        name: apache2
        state: restarted
      become: yes
  tasks:
    - name: 'Instala pacotes de dependencia do sistema operacional'
      apt:
        update_cache: yes
        cache_valid_time: 3600 #1 hora       
        name: "{{ item }}"
        state: latest
      become: yes
      with_items:
        - php5
        - apache2
        - libapache2-mod-php5
        - php5-gd
        - libssh2-php
        - php5-mcrypt
        - mysql-server-5.6
        - python-mysqldb
        - php5-mysql

    - name: 'Cria o banco no MySQL'
      mysql_db:
        name: wordpress
        login_user: root
        state: present

    - name: 'Cria usuario no MySQL'
      mysql_user:
        login_user: root
        name: wordpress_user
        password: 12345
        priv: 'wordpress.*:ALL'
        state: present

    - name: 'Baixa o arquivo de instalacao do Wordpress'
      get_url:
        url: https://wordpress.org/latest.tar.gz'
        dest: '/tmp/wordpress.tar.gz'
        mode: 0440

    - name: 'Descompacta o wordpress'
      unarchive:
        src: '/tmp/wordpress.tar.gz'
        dest: '/var/www/'
        remote_src: yes
      become: yes

    - copy:
        src: '/var/www/wordpress/wp-config-sample.php'
        dest: '/var/www/wordpress/wp-config.php'
        remote_src: yes
      become: yes

    - name: 'Configura o wp-config com as entradas do banco de dados'
      replace:
        path: '/var/www/wordpress/wp-config.php'
        regexp: "{{ item.regex }}"
        replace: "{{ item.value }}"
        backup: yes
      with_items:
        - { regex: 'database_name_here', value: 'wordpress'}
        - { regex: 'username_here', value: 'wordpress_user'}
        - { regex: 'password_here', value: '12345'}
      become: yes

    - name: 'Configura Apache para servir o Wordpress'
      copy:
        src: 'files/000-default.conf'
        dest: '/etc/apache2/sites-available/000-default.conf'
      notify:
        - restart apache
      become: yes

Quando rodo o comando: ansible-playbook -i hosts provisioning.yml

kalil@debian:~/Ansible/teste$ ansible-playbook -i hosts provisioning.yml

PLAY [all] ***************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************
fatal: [172.17.177.40]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: @@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\n@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @\r\n@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r\nIT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\r\nSomeone could
be eavesdropping on you right now (man-in-the-middle attack)!\r\nIt is also possible that a host key has just been changed
.\r\nThe fingerprint for the ECDSA key sent by the remote host is\nSHA256:Hb5n/BgrDfT5dMkFRctB+WE+CQ5s/dJT+r4mtK6xuao.\r\n
Please contact your system administrator.\r\nAdd correct host key in /home/kalil/.ssh/known_hosts to get rid of this messa
ge.\r\nOffending ECDSA key in /home/kalil/.ssh/known_hosts:1\r\n  remove with:\r\n  ssh-keygen -f \"/home/kalil/.ssh/known
_hosts\" -R 172.17.177.40\r\nECDSA host key for 172.17.177.40 has changed and you have requested strict checking.\r\nHost
key verification failed.\r\n", "unreachable": true}
        to retry, use: --limit @/home/kalil/Ansible/teste/provisioning.retry

PLAY RECAP ***************************************************************************************************************
172.17.177.40              : ok=0    changed=0    unreachable=1    failed=0

Me dê um help

Oi Kalil,

O problema está no arquivo known_host que associa a IP da VM com a chave publica nela. Como vc recriou a VM tbm foi criado uma nova chave publica (e privada) , no entanto no arquivo known_host continua a entrada antiga. Para resolver esse problema, vc pode:

  • ou apagar o arquivo known_host na pasta /home/kalil/.ssh/
  • ou desabilitar o uso desse arquivo: ` export ANSIBLE_HOST_KEY_CHECKING=False Mais infos na documentacao do Ansible:

https://docs.ansible.com/ansible/latest/user_guide/intro_getting_started.html#host-key-checking

O comando vagrant ssh usa o localhost para se conectar a VM e faz um port-forwarding, por isso funcionou.

abs

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