I want to execute the shell command, by becoming superuser, going to user directory and executing command, but I am failing in my attempt to do so, Everytime I get stuck with error.
playbook: sudo.yml
---
- name: Test playbook
hosts: targets
gather_facts: false
tasks:
- name: install kubernetes
shell: |
export https_proxy=proxy
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet
become: true
become_user: tania
become_method: su
Command: $ ansible-playbook playbooks/sudo.yml -i hosts --ask-become-pass
Error:
TASK [install kubernetes] ****************************************************************************************************
fatal: [machine1]: FAILED! => {"changed": true, "cmd": "export https_proxy=proxy\nyum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes\nsystemctl enable --now kubelet\n", "delta": "0:10:04.325228", "end": "2023-06-16 10:45:53.301934", "msg": "non-zero return code", "rc": 1, "start": "2023-06-16 10:35:48.976706", "stderr": "sudo: timed out reading password\nsudo: timed out reading password", "stderr_lines": ["sudo: timed out reading password", "sudo: timed out reading password"], "stdout": "", "stdout_lines": []}
I do not want to execute command as: sudo < command > but as sudo -i then command
Ansible.cfg
[defaults]
interpreter_python = /usr/bin/python2
inventory = $HOME/obsw_ansible/hosts
playbook_dir = $HOME/obsw_ansible/playbooks/
remote_user = $USER
log_path = /var/log/ansible.logs
display_skipped_hosts = True
system_warnings = True
show_custom_stats = True
sudo_user = $USER
host_key_checking = False
ask_sudo_pass = False
remote_port = 22
deprecation_warnings = False
[inventory]
enable_plugins = ini, yaml
[privilege_escalation]
become_method = sudo
become_user = $USER
become_ask_pass = True
[paramiko_connection]
host_key_auto_add = True
[connection]
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
$ ansible --version
ansible [core 2.11.12]
config file = /home/tania/obsw_ansible/ansible.cfg
configured module search path = ['/home/tania/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
ansible collection location = /home/tania/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/local/bin/ansible
python version = 3.6.8 (default, Jan 11 2023, 08:43:50) [GCC 8.5.0 20210514 (Red Hat 8.5.0-16)]
jinja version = 2.10.1
libyaml = True
I am providing password still getting error. please help
Suggested changes to playbook or workaround approach. Inspite of providing the password I am still getting same error. Please suggest what am I missing.