实例:vi test.yml
---
- hosts: tx
remote_user: lighthouse
tasks:
- name: df
shell: df -h
register: shell_result
- debug:
var: shell_result.stdout_lines
执行效果如下:
ansible-playbook test.yml
PLAY [tx] *****************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************
ok: [42.xxx.xxx.xxx]
TASK [df] *****************************************************************************************************************************************************************
changed: [42.xxx.xxx.xxx]
TASK [debug] **************************************************************************************************************************************************************
ok: [42.xxx.xxx.xxx] => {
"shell_result.stdout_lines": [
"Filesystem Size Used Avail Use% Mounted on",
"udev 461M 0 461M 0% /dev",
"tmpfs 99M 6.1M 93M 7% /run",
"/dev/vda1 40G 5.4G 33G 15% /",
"tmpfs 493M 24K 493M 1% /dev/shm",
"tmpfs 5.0M 0 5.0M 0% /run/lock",
"tmpfs 493M 0 493M 0% /sys/fs/cgroup",
"tmpfs 99M 0 99M 0% /run/user/1000"
]
}
PLAY RECAP ****************************************************************************************************************************************************************
42.xxx.xxx.xxx : ok=3 changed=1 unreachable=0 failed=0