错误:ansible需要一个json模块,没有找到

时间:2015-02-07 09:59:53

标签: json ansible

执行ansible ping模块时出错

bash ~ ansible webservers  -i inventory -m ping  -k  -u root -vvvv
SSH password: 
<~> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO ~
<my-lnx> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO my-lnx
~ | FAILED => FAILED: [Errno 8] nodename nor servname provided, or not known
<my-lnx> REMOTE_MODULE ping
<my-lnx> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582 && echo $HOME/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582'
<my-lnx> PUT /var/folders/8n/fftvnbbs51q834y16vfvb1q00000gn/T/tmpP6zwZj TO /root/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582/ping
<my-lnx> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582/ping; rm -rf /root/.ansible/tmp/ansible-tmp-1423302966.66-77716810353582/ >/dev/null 2>&1'
my-lnx | FAILED >> {
    "failed": true, 
    "msg": "Error: ansible requires a json module, none found!", 
    "parsed": false
}

这是我的库存文件

bash ~ cat inventory 
[webservers]
my-lnx  ansible_ssh_host=my-lnx ansible_ssh_port=22

我也在客户端和远程机器上安装了simplejosn模块

bash ~ pip list | grep json
simple-json (1.1)
simplejson (3.6.5)

2 个答案:

答案 0 :(得分:15)

我认为您需要安装python-simplejson模块。

首先尝试运行此命令,然后运行所需的命令:

 ansible webservers -i inventory -m raw -a "sudo yum install -y python-simplejson"  -k  -u root -vvvv

我想它的旧Red Hat / CentOS系统。

答案 1 :(得分:10)

如果您不想或无法在远程服务器上安装python-simplejson模块,您可以简单地请求原始输出:

> ansible webservers -i inventory -m ping -m raw

或者像我一样,将它添加到我的〜/ .bash_profile

alias ansible="ansible -m raw"

# And then simply running:
> ansible webservers -i inventory -m ping