Debug School

Umashankar
Umashankar

Posted on

Run shell script and display output

root@ip-172-31-87-83:~/uma# ansible-playbook -i inventory gitget.yaml -u ubuntu --key-file=node.pem -b

PLAY [Install git and wget] *****************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************
ok: [54.89.178.94]

TASK [Install git] **************************************************************************************************************************************************************************
ok: [54.89.178.94]

TASK [Install wget] *************************************************************************************************************************************************************************
ok: [54.89.178.94]

TASK [Execute the shell script] *************************************************************************************************************************************************************
changed: [54.89.178.94]

TASK [Print return information from the previous task] **************************************************************************************************************************************
ok: [54.89.178.94] => {
"msg": "Installed git wget "
}

TASK [Display script output] ****************************************************************************************************************************************************************
ok: [54.89.178.94] => {
"script_output.stdout_lines": [
"Filesystem Size Used Avail Use% Mounted on",
"/dev/root 29G 3.4G 26G 12% /",
"tmpfs 987M 160K 986M 1% /dev/shm",
"tmpfs 395M 1.2M 394M 1% /run",
"tmpfs 5.0M 0 5.0M 0% /run/lock",
"/dev/xvda15 105M 6.1M 99M 6% /boot/efi",
"tmpfs 198M 4.0K 198M 1% /run/user/1000"
]
}

PLAY RECAP **********************************************************************************************************************************************************************************
54.89.178.94 : ok=6 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

root@ip-172-31-87-83:~/uma#

root@ip-172-31-87-83:~/uma# cat gitget.yaml

  • name: Install git and wget hosts: web

tasks:

  • name: Install git ansible.builtin.apt: name: "git" state: present
  • name: Install wget ansible.builtin.apt: name: "wget" state: present
  • name: Execute the shell script
    shell: /root/uma/myscript.sh
    register: script_output

  • name: Print return information from the previous task
    ansible.builtin.debug:
    msg: "Installed git wget "

  • name: Display script output
    debug:
    var: script_output.stdout_lines
    root@ip-172-31-87-83:~/uma#

Top comments (0)