0

I have the following ansible playbook:

- hosts: myhosts
  gather_facts: no

  tasks:
    - debug:
        msg: just a test message

When I run that from command line I get:

PLAY RECAP ****************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

So that works just fine. But if I add:

- hosts: myhosts
  gather_facts: no


  tasks:
    - debug:
        msg: just a test message
    - name: Another task
      command: echo "Do whatever you want to"

It fails with:

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   

From what i have googled Ansible requires python2.7 for most of its functionality - which I currently don't have installed. So is the above error caused by missing Python2.7 or something else?

u123
  • 15,603
  • 58
  • 186
  • 303

1 Answers1

2

So is the above error caused by missing Python2.7

Yes. Ansible requires Python for almost every module except: raw, script.

You can install Python with raw module first and then proceed with other tasks. See this answer.

Example of tasks that don't require 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 }}"
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Ok, when I run you updated example - using raw instead of command - the text "Do whatever you want to" is not printed to console, it just says changed: [localhost]. So how do I use raw to execute a bash command on the remote? – u123 Dec 01 '17 at 19:44
  • I've update example with debug output to check results. Or you can execute playbook with increased verbosity (`-vv`) to see modules' output. – Konstantin Suvorov Dec 01 '17 at 19:56