Is it possible to add a password to the "become: true" method in a Ansible playbook?

274 Views Asked by At

I have a question regarding the use of become: true.

I have been researching for a while if there is a way to run the tasks as sudo. I don't want to give -k -K when I run the playbook or something like that.

My playbook should run automatically with a pipeline and that's why I can't use that. I have a vault where my encrypted passwords are. I can output my password in clear text like this:

- name: test1 
  ansible.builtin.debug: 
    msg: "{{ passwords.user_sudo_rights }}"

I would like something for example so

- hosts: all 
  become: true 
  become_password: "{{ passwords.user_sudo_rights }}"

to become sudo with a password.

I have also tried the variant with the /vars/group_vars.yml but it does not work either.

ansible_become: true 
ansible_become_method: sudo 
ansible_become_pass: "{{ user_sudo_rights }}"

I am not allowed by company policy to use passwordless sudo

0

There are 0 best solutions below