1
resposta

Problema ao rodar ansible-playbook provisioning.yml -u vagrant -i hosts

Ao colocar o codigo ansible-playbook provisioning.yml -u vagrant -i hosts, aparece a seguinte mensagem de erro:

PLAY [database] **************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************
fatal: [172.17.177.42]: 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:kfqcMsHVRq5FRLgIbxP77kF1d56Yr7QGbxrGO1Gr5KA.\r\nPlease contact your system administrator.\r\nAdd correct host key in /home/heldem/.ssh/known_hosts to get rid of this message.\r\nOffending ECDSA key in /home/heldem/.ssh/known_hosts:2\r\n  remove with:\r\n  ssh-keygen -f \"/home/heldem/.ssh/known_hosts\" -R \"172.17.177.42\"\r\nECDSA host key for 172.17.177.42 has changed and you have requested strict checking.\r\nHost key verification failed.", "unreachable": true}

PLAY RECAP *******************************************************************************************************************
172.17.177.42              : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0

O código do provisioning é:

---
- hosts: database
  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:
        - mysql-server-5.6
        - python-mysqldb

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

    - name: 'Cria usuario no MySQL'
      mysql_user:
        login_user: root
        name: wordpress_user
        password: 12345
        priv: 'wordpress_db.*:ALL'
        state: present
        host: '{{ item }}'
      with_items:
        - 'localhost'
        - '127.0.0.1'
        - '172.17.177.40'

    - name: 'Configura MySQL para aceitar conexões remotas'
      copy:
        src: 'files/my.cnf'
        dest: '/etc/mysql/my.cnf'
      become: yes
      notify:
       - restart mysql


- hosts: wordpress
  handlers:
    - name: restart apache
      service:
        name: apache2
        state: restarted
      become: yes
  tasks:
    - name: 'Instala pacotes de dependencia do sistema operacional'
      apt:
        update_cache: yes #atualizando o package list
        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
        - php5-mysql

    - 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_db'}
        - { regex: 'username_here', value: 'wordpress_user'}
        - { regex: 'password_here', value: '12345'}
        - { regex: 'localhost', value: '172.17.177.42'}
      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
1 resposta

Cheguei a ter um problema similar. O que eu fiz pra resolver foi apagar o conteúdo do arquivo /home/user/.ssh/know_hosts depois destrui as máquinas e recriei novamente vagrant destroy && vagrant up e pronto, resolvido.