Search code examples
ansible

Ansible gets stuck on tasks having key become: true


When I run my playbooks, Ansible gets stuck on tasks having become: true , as if it was waiting for some user prompt, even if I pass it the --ask-become-pass flag or the ansible_become_pass in --extra-vars flag.

Example of task:

- name: copy the ansible-am project cron to /etc/cron.d/
  become: true
  timeout: 5
  ignore_errors: true
  ansible.builtin.shell:
    cmd: |
      cp {{ ansible_am_cron_absfilepath }} {{ root_ansible_am_cron_filepath }}

  register: task1_result
  failed_when: task1_result.rc != 0

Example of how I call the playbook

ansible-playbook -vvvvvv --extra-vars='ansible_become_pass=mypassword' playbooks/my_playbook.yml

ansible-playbook -vvvvvv --ask-become-pass playbooks/my_playbook.yml

Unfortunately, adding log levels shows that no password is given:

Check if the string is present in the file...    
Using module file /home/my_path/ansible-venv/lib/python3.7/site-packages/ansible/modules/command.py    
Pipelining is enabled.
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: my_user
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=eusofmetqrwweecthgwo] password:" -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-eusofmetqrwweecthgwo ; /home/my_path/ansible-venv/bin/python3.7'"'"' && sleep 0'
  localhost failed: {
    "changed": false,
    "msg": "The shell action failed to execute in the expected time frame (5) and was terminated"
}

Solution

  • Solved by running the playbook launch command with sudo:

    sudo ansible-playbook playbooks/my_playbook.yml