Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: Shared connection to xxx closed

Hello guys I make a simple playbook to practice with Ansible but I have a problem when I try to run the playbook (ansible-playbook -i hosts.ini playbook.yml) to configure an instance ec2 the output returns:

> fatal: [XX.XXX.XXX.XXX]: FAILED! => {
>     "changed": false, 
>     "failed": true, 
>     "invocation": {
>         "module_name": "setup"
>     }, 
>     "module_stderr": "Shared connection to XXX.XXX.XXX.XXX closed.\r\n", 
>     "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 
>     "msg": "MODULE FAILURE" }     to retry, use: --limit @/home/douglas/Ansible/ansible_praticing/projeto2.retry
> 
> PLAY RECAP
> *********************************************************************
> XX.XXX.XXX.XXX             : ok=0    changed=0    unreachable=0    failed=1

When I try to connect with the instance via ssh -i ~/.ssh/key.pem [email protected] it works well but the provisioning not.

My playbook:

- hosts: projeto
  sudo: True
  remote_user: ubuntu
  vars_files:
    - vars.yml

  tasks:
    - name: "Update"
      apt: update_cache=yes

    - name: "Install the Ansible"
      apt: name=ansible state=latest

    - name: "Installt the mysql"
      apt:
      args:
        name: mysql-server
        state: latest

    - name: "Install the Nginx"
      apt:
      args:
        name: nginx
        state: latest

My hosts.ini is also ok (with public ip of aws ec2 instance) and I put the public key (~/.ssh/id_rsa.pem of local machine) in the ~/.ssh/authorized_keys file, inside of the instance.

In the last week (Friday) this playbook was working well.

What am I doing wrong?

like image 774
Douglas Dias da Silva Avatar asked Nov 21 '16 13:11

Douglas Dias da Silva


1 Answers

Maybe my answer is too late but I faced the same problem today. I have an Ubuntu 16.04 instance running on my EC2. I think, since it has Python 3 (Python 3.5) as its default Python installation. Hence, ansible is not able to find the required Python directory (/usr/bin/python). I got around this issue by changing the ansible Python interpreter to Python 3.

I added ansible_python_interpreter=/usr/bin/python3 to my inventory file and did not have to change the playbook.

Reference - http://docs.ansible.com/ansible/latest/python_3_support.html

like image 62
sushrut619 Avatar answered Sep 20 '22 09:09

sushrut619