查看 Ansible 的 Register 变量内容

本文介绍了两种在Ansible中查看register变量内容的方法。第一种是在playbook命令行使用-v参数,例如在执行`ansible-playbook -v test.yml`时会显示register变量`result`的详细信息,包括执行的命令及输出的JSON数据。第二种方法是通过debug模块,如在`debug-register.yml`中使用debug任务显示变量`say_hi`的详细内容,包括stdout等字段。
摘要由CSDN通过智能技术生成

方式1. 在playbook 命令加入参数 -v 就可以打印出 register 的内容

playbook内容
[root@ansible1 ~]# cat test.yml

  • hosts: localhost
    gather_facts: no
    tasks:
    • name: test with register
      shell: cat /root/input.json
      register: result

playbook引用到的json文件内容
[root@ansible1 ~]# cat /root/input.json
{
services {
vsftpd
}
}

运行playbook
[root@ansible1 ~]# ansible-playbook -v test.yml
Using /etc/ansible/ansible.cfg as config file
/etc/ansible/hosts did not meet host_list requirements, check plugin documentation if this is unexpected
/etc/ansible/hosts did not meet script requirements, check plugin documentation if this is unexpected

PLAY [localhost] ***************************************************************************************************</

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值