成功最有效的方法就是向有经验的人学习!

ansible-playbook显示执行shell的模块的返回结果

实例: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   
赞(2) 打赏
未经允许不得转载:陈桂林博客 » ansible-playbook显示执行shell的模块的返回结果
分享到

大佬们的评论 抢沙发

全新“一站式”建站,高质量、高售后的一条龙服务

微信 抖音 支付宝 百度 头条 快手全平台打通信息流

橙子建站.极速智能建站8折购买虚拟主机

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏

登录

找回密码

注册