NOTE: This is scenario with vitualbox running a minimal ubuntu image used as a remote host being accessed from ubuntu 16.04
I am a beginner using ansible to run a shell script on a remote server, but it seems to freeze, i dont recieve any logs even after using "-vvv" in arguments.
After a little debugging i figured that the problem was with sudo apt-get update used in the shell script.
If i pass the password as an argument from ansible plabook to the shell file and later use it as echo "$PASS" | sudo -S apt-get update , the script seems to work.
How do i configure my ansible Playbook so that it doesnot freeze on the password prompt on executing sudo apt-get update inside the shell file.
and i need to use a specific user account and password instead of root.
I am passing host, user and pass as --extra-vars to the playbook,
{{ host }} is the ip address of the remote host.
{{ user }} is a user account on the remote machine.
{{ pass }} is the password of the user account on the remote machine.
Here is my ansible playbook -
---
- hosts: "{{ host }}"
remote_user: "{{ user }}"
vars:
ansible_become_pass: "{{ pass }}"
tasks:
- name: Move test.sh file to remote
copy:
src: ./../scripts/test.sh
dest: /home/{{ user }}/new/test.sh
- name: Executing the test.sh script
command: sh test.sh
args:
chdir: /home/{{ user }}/new/
become: yes
become_user: "{{ user }}"