- name: Print debug infomation eg
hosts: test2
gather_facts: F
tasks:
- name: Command run line
shell: date
register: result
- name: Show debug info
debug: var=result.stdout verbosity=

ansible playbook可以将多个命令组合来执行,但是很多时候我们需要接收服务器的反馈,所以debug模块就非常重要了。

模块说明

调试模块,用于在调试中输出信息 常用参数: msg:调试输出的消息 var:将某个任务执行的输出作为变量传递给debug模块,debug会直接将其打印输出 verbosity:debug的级别(默认是0级,全部显示)

例程:

- name: Print debug infomation eg1
hosts: test2
gather_facts: F
vars:
user: jingyong
tasks:
- name: Command run line
shell: date
register: result
- name: Show debug info
debug: var=result verbosity=

程序是将命令date返回信息使用debug模块打印出来。

返回结果如下:

PLAY [Print debug infomation eg] ***********************************************

TASK [Show debug info] ********************************************************* ok: [192.168.0.1] ={ "result": { "changed": true, "cmd": "date", "delta": "0:00:00.002400", "end": "2016-08-27 13:42:16.502629", "rc": 0, "start": "2016-08-27 13:42:16.500229", "stderr": "", "stdout": "2016年 08月 27日 星期六 13:42:16 CST", "stdout_lines": [ "2016年 08月 27日 星期六 13:42:16 CST" ], "warnings": [] } } ok: [192.168.0.2] ={ "result": { "changed": true, "cmd": "date", "delta": "0:00:00.003847", "end": "2002-01-12 03:08:37.493383", "rc": 0, "start": "2002-01-12 03:08:37.489536", "stderr": "", "stdout": "2002年 01月 12日 星期六 03:08:37 CST", "stdout_lines": [ "2002年 01月 12日 星期六 03:08:37 CST" ], "warnings": [] } }

PLAY RECAP ********************************************************************* 192.168.0.1 : ok=2changed=1unreachable=0failed=0   192.168.0.1 : ok=2changed=1unreachable=0failed=0

可以看到debug不光输出了date命令结果,还返回了很多相关调试信息,只需要date返回值,可以使用变量属性过滤 如:result.stdout 就是命令的返回值。

程序改成:

运行结果:

PLAY [Print debug infomation eg] ***********************************************

TASK [Command run line] ******************************************************** changed: [192.168.0.1] changed: [192.168.0.2]

TASK [Show debug info] ********************************************************* ok: [192.168.0.1] ={ "result.stdout": "2002年 01月 12日 星期六 03:16:26 CST" } ok: [192.168.0.2] ={ "result.stdout": "2016年 08月 27日 星期六 13:50:05 CST" }

PLAY RECAP ********************************************************************* 192.168.0.1  : ok=3changed=1unreachable=0failed=0   192.168.0.2  : ok=3changed=1unreachable=0failed=0

ansible debug模块学习笔记的更多相关文章

  1. Python 日期时间处理模块学习笔记

    来自:标点符的<Python 日期时间处理模块学习笔记> Python的时间处理模块在日常的使用中用的不是非常的多,但是使用的时候基本上都是要查资料,还是有些麻烦的,梳理下,便于以后方便的 ...

  2. Python 3之str类型、string模块学习笔记

    Windows 10家庭中文版,Python 3.6.4, Python 3.7官文: Text Sequence Type — str string — Common string operatio ...

  3. 【Python】logging模块学习笔记

    因为做接口自动化测试遇到的一个代码逻辑上的问题,又不知道具体问题出在哪里,所以在模块化代码之前,先学习下python的日志模块logging. 入门1 入门2 日志级别大小关系为:CRITICAL & ...

  4. Scikit-Learn模块学习笔记——数据集模块datasets

    scikit-learn 的 datasets 模块包含测试数据相关函数,主要包括三类: datasets.load_*():获取小规模数据集.数据包含在 datasets 里 datasets.fe ...

  5. Python装饰器、metaclass、abc模块学习笔记

    (博客原创作品,转载请注明出处!) 最近接触到了Python中的decorator,metaclass,abc Module,six.add_metaclass等内容,这里做一个简单的笔记. 主要资源 ...

  6. Python shutil 模块学习笔记

    学于https://automatetheboringstuff.com shutil 名字来源于 shell utilities,有学习或了解过Linux的人应该都对 shell 不陌生,可以借此来 ...

  7. Python模块学习笔记

    1.作用域 私有private:用'_x'或'__xx'表示,如,_a,__ab; 公有public: 如 a,b; 特殊变量,可被直接引用,如:__author__,__name__,命名变量时一般 ...

  8. Scikit-Learn模块学习笔记——数据预处理模块preprocessing

    preprocessing 模块提供了数据预处理函数和预处理类,预处理类主要是为了方便添加到 pipeline 过程中. 数据标准化 标准化预处理函数: preprocessing.scale(X, ...

  9. Python requests模块学习笔记

    目录 Requests模块说明 Requests模块安装 Requests模块简单入门 Requests示例 参考文档   1.Requests模块说明 Requests 是使用 Apache2 Li ...

随机推荐

  1. 【LeetCode】149. Max Points on a Line

    Max Points on a Line Given n points on a 2D plane, find the maximum number of points that lie on the ...

  2. Android中的Service使用

    Service的生命周期 (适用于2.1及以上) 1. 被startService的无论是否有任何活动绑定到该Service,都在后台运行.onCreate(若需要) -> onStart(in ...

  3. CentOS 6.7下配置 yum 安装 Nginx。

    第一步,在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo: cd /etc/yum.repos.d/ vim nginx.repo 填写如下内容: [nginx]nam ...

  4. python练习笔记——分解质因数

    分解质因数:输入一个正整数,分解质因数:如输入: 90   则打印: 90 = 2 * 3 * 3 * 5 get_str = input("请输入一个100以内的正整数,以分解质因数:&q ...

  5. ant批量运行Jmeter脚本遇到 Content is not allowed in prolog.问题及解决方案

    在执行 最后生成报告的 task 时,一直报下面这个错: TransformerException,  Content is not allowed in prolog. 解决方法:需要修改jmete ...

  6. notepad++与ISE/Vivado关联

    转自:http://www.cnblogs.com/ninghechuan/p/6172237.html 1.notepad++与vivado关联 打开vivado软件,选择菜单栏“Tools——&g ...

  7. Wavenet运行

    作者:桂. 时间:2017-05-10  19:17:32 链接:http://www.cnblogs.com/xingshansi/p/6832219.html 一.环境 python3.5 Win ...

  8. php 的session机制 和ecshop session机制

    一.默认机制,用磁盘文件来实现PHP会话.php.ini配置:session.save_handler = files 1.session_start() A. session_start()是ses ...

  9. unity 查看prefab层次

    点那个箭头,可以展开:

  10. libgdx 1.4.1公布

    (转载自http://www.libgdx.cn/topic/4/libgdx-1-4-1%E5%8F%91%E5%B8%83) libgdx从未停止进步的脚步.10月10日.libgdx1.4.1公 ...