blue
blue

Reputation: 1

Ansible playbook script requires "press enter to continue"

I like to create an Ansible playbook which utilize a script (pre-requirements.sh) that requires "press enter to continue".

The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_expect_payload_x4zBUF/ansible_expect_payload.zip/ansible/modules/commands/expect.py", line 108, in <module>
ImportError: No module named pexpect
fatal: [server1]: FAILED! => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "invocation": {
        "module_args": {
            "chdir": null,
            "command": "pre-requirements.sh",
            "creates": null,
            "echo": false,
            "removes": null,
            "responses": {
                "PRESS \\<ENTER\\> TO CONTINUE:": ""
            },
            "timeout": 30
        }
    },
    "msg": "Failed to import the required Python library (pexpect) on server1's Python /usr/bin/python. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"
}

Expected output is for the playbook to wait for enter to be pressed on users keyboard.

Above error is displayed.

Is there any other module or method to use for user input when running ansible playbook?

I've have done yum install pextect but the version is not compatible with our Ansible.

TASK [Running pre-req script] ***************************************************************************************************************************************************************
fatal: [server1]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "Insufficient version of pexpect installed (2.3), this module requires pexpect>=3.3. Error was 'module' object has no attribute 'runu'"}

Upvotes: 0

Views: 1241

Answers (1)

phanaz
phanaz

Reputation: 1524

The Ansible module expect requires the Python package pexpect.

  1. check that python3-pip is installed (yum install python3-pip)

    - name: install python's pip
      yum:
        name: python3-pip
    
  2. install the Python package pexpect

    - name: install pexpect via pip
      pip:
        name: pexpect
    
  3. use the Ansible module expect

    - name: run shell script and answer it's questions
      expect:
        command: "/path/to/your/script.sh"
        responses:
        "scripts question:": "your answer"
    

Upvotes: 0

Related Questions