我有以下Ansible Playbook:
- hosts: myhosts
gather_facts: no
tasks:
- debug:
msg: just a test message
当我从命令行运行时,我会得到:
PLAY RECAP ****************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
这样可以正常工作。但是,如果我添加:
- hosts: myhosts
gather_facts: no
tasks:
- debug:
msg: just a test message
- name: Another task
command: echo "Do whatever you want to"
它失败了:
TASK [Another task] *******************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to localhost closed.rn", "module_stdout": "/bin/sh: 1: /usr/bin/python: not foundrn", "msg": "MODULE FAILURE", "rc": 0}
to retry, use: --limit @/home/user/sandbox/ansible-vps/foo.retry
PLAY RECAP ****************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1
根据我的谷歌搜索,大多数功能都需要python2.7 - 我目前尚未安装。因此,上述错误是由于缺少python2.7还是其他错误?
因此,缺少python2.7
引起的上述错误也是如此
是。Ansible几乎需要python,除了:raw
,script
。
您可以先使用raw
模块安装Python,然后继续执行其他任务。看到此答案。
不需要python的任务的示例:
- hosts: myhosts
gather_facts: no
tasks:
- debug:
msg: just a test message
- name: Another task
raw: /bin/bash -c 'some-command with-parameter'
register: cmd_res
- debug:
msg: "{{ cmd_res.stdout }}"