侧边栏壁纸
博主头像
张种恩的技术小栈博主等级

行动起来,活在当下

  • 累计撰写 748 篇文章
  • 累计创建 65 个标签
  • 累计收到 39 条评论

目 录CONTENT

文章目录

ansible的debug模块

zze
zze
2020-03-28 / 0 评论 / 0 点赞 / 373 阅读 / 1892 字

不定期更新相关视频,抖音点击左上角加号后扫一扫右方侧边栏二维码关注我~正在更新《Shell其实很简单》系列

此文章为「ansible笔记(2)之常用模块」的子文章。

见名知义,debug 模块的作用就是帮助我们进行调试的,debug 模块可以帮助我们把信息输出到 ansible 控制台上,以便我们能够定位问题。

参数说明:

  • msg:指定输出的文本字符串,字符串中可以以 {{变量名}} 的形式输出变量值;
  • var:直接指定一个要输出的变量;

那么我们先来看一个 debug 模块的 playbook 小示例,如下:

---
- hosts: B
  remote_user: root
  tasks:
  - name: touch testfile
    file:
      path: /testdir/testfile
      state: touch
  - name: debug demo
    debug:
      msg: this is debug info,The test file has been touched

上述 playbook 表示 touch 完对应的文件以后,在 ansible 控制台中输出我们指定的信息,那么我们运行一下这个测试剧本,看一下效果,如下:

$ ansible-playbook test.yml 

PLAY [B] ************************************************************************************************************************************

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

TASK [touch testfile] ***********************************************************************************************************************
changed: [B]

TASK [debug demo] ***************************************************************************************************************************
ok: [B] => {
    "msg": "this is debug info,The test file has been touched"
}

PLAY RECAP **********************************************************************************************************************************
B                          : ok=3    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

如上,自定义信息已经输出在 ansible 控制台中。

debug 模块的 msg 参数中还可以通过 {{var_name}} 的方式输出变量的值,这里就不做演示了。

0

评论区