ansible中不需要python2.7的任务示例?

时间:2017-12-01 19:33:41

标签: python ansible

我有以下ansible剧本:

- 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.\r\n", "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", "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   

从我用Google搜索的内容来看,Ansible需要python2.7来实现其大部分功能 - 我目前还没有安装它。因缺少Python2.7或其他原因导致上述错误吗?

1 个答案:

答案 0 :(得分:2)

  

因缺少Python2.7导致上述错误

是。 Ansible几乎每个模块都需要Python,除了:rawscript

您可以先使用raw模块安装Python,然后继续执行其他任务。请参阅this answer

不需要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 }}"