How to process a command asking for inputs with an

2019-07-13 23:59发布

问题:

I'm learning Ansible and I'm wondering how to write a task to process the following command:

$<command> <options>

  username:
  email address:
  password:
  password (check):

The <command> <option> asks for four variables that can be hardcoded in the playbook.

Thank you for any insight you can provide

回答1:

Use expect module:

- hosts: localhost
  tasks:
    - expect:
        command: command option
        responses:
          username: "John Doe"
          email: "joh@doe.com"
          password: "mypass"