Search code examples
ansiblepexpect

Ansible expect adds other character to response and does not enter it


I'm trying to install no-ip's Dynamic Update Client. I'm using the expect module to answer every prompt, but each time the script ask for my password, it adds another character and does not enter the password (the command exceeded timeout).

Here is my task (noip_email and noip_password are variables from a vault. I tried printing them and they are correct).

- name: DNS - install no-ip DUC
  ansible.builtin.expect:
    command: "make install"
    chdir: /usr/local/src/noip
    echo: true
    responses:
      "By typing the number associated with it": "0"
      "login/email": "{{ noip_email }}"
      "password": "{{ noip_password }}"
      "update interval": "20"
      "run something": "n"

I tried to simplify the matching word; using the full sentence; not using variables (from a vault); I tried not to match output (see the second example in ansible's doc), tried a bigger timeout, and also tried adding manual "enter" with \n at the end of the prompt.

None of the solution I tried or found on the internet worked, and I ran out of ideas. I really don't know why it adds another character to the password input, and why it doesn't enter (\n) my password, especially when every other prompt is correct and entered.

System:

  • Ansible 2.13.5
  • Python 3.10
  • Ubuntu 22.04, Raspberry Pi 4 8Gb

Solution

  • I've solved my issue by using the expect binary with the shell module.

    - name: DNS - install no-ip DUC
      ansible.builtin.shell: |
        set timeout 30
        spawn make install
    
        expect "number associated"
        send "0\n"
    
        expect "email"
        send "{{ noip_email }}\n"
    
        expect "password"
        send "{{ noip_password }}\n"
    
        expect "update"
        send "20\n"
    
        expect "run"
        send "n\n"
      args:
        executable: /usr/bin/expect
        chdir: /usr/local/src/noip