Ansible + 10.11.6

不羁岁月 提交于 2019-12-04 02:13:30

问题


I'm having a weird issue with Ansible on a (very) clean install of 10.11.6. I've installed brew, zsh, oh-my-zsh, Lil' snitch and 1password (and literally nothing else). I installed ansible with...

brew install ansible

... which was successful. I then went to a preexisting (and crazy simple) Ansible project and did an...

ansible -m ping all

It then asked me to enter my SSH passphrase. I've reinstated the keys from my previous install but I hadn't previously ssh'd into the server. I entered the passphrase and ansible returned...

$ ansible -m ping all               
host1 | UNREACHABLE! => {
"changed": false, 
"msg": "Failed to connect to the host via ssh.", 
"unreachable": true
}

I then ssh'd into the server to check all was well, and it connected without any problems.

I then re-ran...

$ ansible -m ping all

and it returned...

host1 | FAILED! => {
"changed": false, 
"failed": true, 
"module_stderr": "", 
"module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", 
"msg": "MODULE FAILURE", 
"parsed": false
}

... which is a bit weird? It seems to be saying it can't find python anymore, despite it finding it first time around?

$ which python returns /usr/bin/python

$ python --version returns Python 2.7.10

$ which ansible returns /usr/local/bin/ansible

$ ansible --version returns

ansible 2.1.1.0
config file = /pathtoproject/ansible.cfg
configured module search path = Default w/o overrides

I've deliberately not installed pyenv, virtualenv etc.

/usr/bin/python is definitely there, and I can run python without any problems.

Help?! :-) I'm a Ruby dev and I can't help but think I'm missing something obvious, but as I understand it all the versions check out and everything should be working. I tried changing my shell to sh and rerunning ansible -m ping all but it fails in the same way.

Any ideas?


回答1:


This happens if there is no python installed on the remote hosts. The ansible documentation suggests doing this for every host by hand: ansible myhost --sudo -m raw -a "yum install -y python2 python-simplejson"

However I think it's nicer to bootstrap all of your hosts with this snippet at the start of you playbook:

- name: Bootrstrap python hosts: localhost tasks: raw: sudo apt-get update && sudo apt-get -y python-simplejson delegate_to: '{{ item }}' with_items: {{ groups["hosts"] }}




回答2:


I had a similar issue, but the "fix" was stranger yet: remove Python3 from the host, as Ansible currently supports up to Python 2.7.




回答3:


Python3 don't work with Ansible (....

  1. apt-get install -y python2.7 python-simplejson on remote server. Not necessary remove any other versions.
  2. your permission to id_rsa must be only 'read' - chmod 400 ~/.ssh/id_rsa - either you can get another error "UNPROTECTED PRIVATE KEY FILE!"


来源:https://stackoverflow.com/questions/38799807/ansible-10-11-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!