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

Failed to connect to the host via ssh: Permission denied (publickey,password)

Tive problema de conexão ssh no início do curso, foi resolvido mas ao usar o comando : ansible-playbook provisioning.yml -i /vagrant/hosts

Tive p seguinte retorno: TASK [Gathering Facts] * fatal: [10.10.0.100]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).", "unreachable": true}

Pesquisei aqui no forum e alguns posts ou estão sem retorno ou desistiram da solução (bug etc).

Criei novamente as chaves com ssh-keygen -f id_ansible -t rsa e instalei remotamente com ssh-copy-id -i id_ansible.pub vagrant@10.10.0.100, persistindo o erro.

Alguém teve esse problema e resolveu?

Segue meus arquivos.

VAGRANTFILE Vagrant.configure("2") do |config| config.vm.box = "ubuntu/trusty64"

config.vm.provider "virtualbox" do |v|
    v.memory = 1024
end

config.vm.define "ansible" do |ansible|
  ansible.vm.network "private_network", ip: "10.10.0.101"

  ansible.vm.provision "shell",
    inline: "sudo apt-get purge ansible && \
             apt-get install -y software-properties-common && \
             apt-add-repository ppa:ansible/ansible && \
             apt-get update && \
             apt-get install -y ansible && \
             echo ------------------------------------ END INSTALL ANSIBLE"

  ansible.vm.provision "shell",
    inline: "cp /vagrant/configs/id_ansible /home/vagrant && \
             cp /vagrant/configs/id_ansible.pub /home/vagrant && \
             cp /vagrant/provisioning.yml /home/vagrant && \
             cp /vagrant/hosts /etc/ansible/ && \
             echo ------------------------------------ END CP id_ansible
             chmod 600 /home/vagrant/id_ansible && \
             chown vagrant:vagrant /home/vagrant/id_ansible
             sudo chown vagrant:vagrant /home/vagrant/provisioning.yml" #Addicionado 28/08

 end

config.vm.define "wordpress" do |wordpress|
    wordpress.vm.network "private_network", ip: "10.10.0.100"

wordpress.vm.provision "shell",
    inline: "cat /vagrant/configs/id_ansible.pub >> .ssh/authorized_keys && \
    echo ------------------------------------ END CAT ID_ANSIBLE"
end

end

HOSTS [wordpress] 10.10.0.100 ansible_user=vagrant ansible_ssh_private_key_file="/home/vagrant/id_ansible"

PROVISIONING.YML

  • hosts: all tasks:

    • name: 'Instala pacotes de dependencia do SO' apt: update_cache: yes cache_valid_time: 3600 #1 hora name:

      • php5
      • apache2
      • libapache2-mod-php5
      • php5-gd
      • libssh2-php
      • php5-mcrypt
      • mysql-server-5.6
      • python-mysqldb
      • php5-mysql state: latest become: yes
    • name: 'Cria o banco do MySQL' mysql_db: name: wordpress_db login_user: root state: present

    • name: 'Cria o usuário do MySQL' mysql_user: login_user: root name: wordpress_user password: '12345' priv: 'wordpress_db.*:ALL' state: present

    • name: 'Baixa Instalação do Wordpress' get_url: url: https://br.wordpress.org/latest-pt_BR.tar.gz dest: '/tmp/wordpress.tar.gz'

    • name: 'Descompactar Arquivo' unarchive: src: '/tmp/wordpress.tar.gz' dest: /var/www/ remote_src: yes become: yes

    • name: 'Copiar arquivo Modelo de configuração' 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: 'nome_do_banco_de_dados_aqui', value: 'wordpress_db'}
      • { regex: 'nome_de_usuario_aqui', value: 'wordpress_user'}
      • { regex: 'senha_aqui', 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' become: yes

1 resposta
solução!

RESOLVIDO

Destrui as VMS (estou no windows). Refiz tudo de novo, e ai mudou o erro:

TASK [Configura Apache para servir o Wordpress] **** An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option fatal: [10.10.0.100]: FAILED! => {"changed": false, "msg": "Could not find or access 'files/000-default.conf'\nSearched in:\n\t/home/vagrant/files/000-default.conf\n\t/home/vagrant/files/000-default.conf on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}

Copiei o arquivo abaixo e recebi o mesmo erro. cp /vagrant/files/000-default.conf /home/vagrant

Por fim, o provisioning.yml no campo abaixo e funcionou. src: '/vagrant/files/000-default.conf'