在搞TF(tungstenfabric)时遇到了一些错误,TF通过ansible playbook 来部署的。通常情况下遇到错误都是通过ansibale xxxx –vvv 来详细输出一下。出错的类型如果使某个命令或者代码 还是比较好处理的。如果错误是一个运行中获取的变量就比较麻烦,因为你也不知道应该是什么或者当前的值是什么如果可以动态调试就好好办了。debugger模块就是干这个事情的

debugger模块参数值

always:

无论结果如何,始终调用调试器

never:

无论结果如何,都不要调用调试器

on_failed:

仅在任务失败时才调用调试器

on_unreachable:

仅当主机不可访问时才调用调试器

on_skipped:

仅当跳过任务时才调用调试器

调试测试

  1 ---
2 - name: Ensuring config directories exist
3 debugger: always  #debugger关键字:出发debug条件
4 file:
5 path: "{{ node_config_directory }}/{{ item }}"
6 state: "directory"
7 owner: "{{ config_owner_user }}"
8 group: "{{ config_owner_group }}"
9 mode: "0770"
10 become: true
11 with_items:
12 - "memcached"

开始跑playbook

查看当前执行的TASK任务

TASK [memcached : include_tasks] *******************************************************************

included: /root/deploy/contrail-kolla-ansible/ansible/roles/memcached/tasks/config.yml for 10.49.252.201

TASK [memcached : Ensuring config directories exist] ***********************************************

ok: [10.49.252.201] => (item=memcached)

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> task

TASK: memcached : Ensuring config directories exist

查看当前TASK需要的变量

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> p task.args

{u'group': u'{{ config_owner_group }}',
  u'mode': u'0770',
  u'owner': u'{{ config_owner_user }}',
  u'path': u'{{ node_config_directory }}/{{ item }}',
  u'state': u'directory'}

红色的就是动态获取的变量

获取指定变量(p task_vars['config_own  er_group'])

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> p task_vars['config_own  er_group']

u'root'

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> p task_vars['node_confi  g_directory']

u'/etc/kolla/{{ project }}'

获取所有的动态变量,我这里会有很多只截取部分

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> p task_vars

{u'TSN_EVPN_MODE': False,
  u'action': u'deploy',
  u'admin_protocol': u'http',
  u'analytics_api_ssl_enable': False,
  u'ansible_all_ipv4_addresses': [u'10.49.252.201',
                                  u'192.168.100.1',
                                  u'172.17.0.1'],

………………………………………………….

获取当前task运行结果

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> p result._result

{'changed': False,
  'msg': u'All items completed',
  'results': [{'_ansible_ignore_errors': None,
               '_ansible_item_result': True,
               '_ansible_no_log': False,
               '_ansible_parsed': True,
               u'changed': False,
               u'diff': {u'after': {u'path': u'/etc/kolla//memcached'},
                         u'before': {u'path': u'/etc/kolla//memcached'}},
               'failed': False,
               u'gid': 0,
               u'group': u'root',
               u'invocation': {u'module_args': {u'attributes': None,
                                                u'backup': None,
                                                u'content': None,
                                                u'delimiter': None,
                                                u'diff_peek': None,
                                                u'directory_mode': None,
                                                u'follow': True,
                                                u'force': False,
                                                u'group': u'root',
                                                u'mode': u'0770',
                                                u'original_basename': None,
                                                u'owner': u'root',
                                                u'path': u'/etc/kolla//memcached',
                                                u'recurse': False,
                                                u'regexp': None,
                                                u'remote_src': None,
                                                u'selevel': None,
                                                u'serole': None,
                                                u'setype': None,
                                                u'seuser': None,
                                                u'src': None,
                                                u'state': u'directory',
                                                u'unsafe_writes': None,
                                                u'validate': None}},
               'item': u'memcached',
               u'mode': u'0770',
               u'owner': u'root',
               u'path': u'/etc/kolla//memcached',
               u'secontext': u'unconfined_u:object_r:etc_t:s0',
               u'size': 6,
               u'state': u'directory',
               u'uid': 0}]}

修改key对应的值

修改变量赋值

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> task_vars['path'] = '/etc/kolla//memcached1'

我们再次查看值是否改变

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> p task_vars['path']

'/etc/kolla//memcached1

重新redo即可

[10.49.252.201] TASK: memcached : Ensuring config directories exist (debug)> redo

ok: [10.49.252.201] => (item=memcached)

ansible debugger 模块的更多相关文章

  1. ansible服务模块和组模块使用

    本篇文章主要是介绍ansible服务模块和组模块的使用. 主要模块为ansible service module和ansible group moudle,下面的内容均是通过实践得到,可以直接运行相关 ...

  2. ansible常用模块用法

    ansible常用模块用法 2015-07-21 10:25 24458人阅读 评论(1) 收藏 举报  分类: Linux(44)   ansible 版权声明:本文为博主原创文章,未经博主允许不得 ...

  3. Linux之ansible 常用模块

    目的 代码发布系统 代码发布:把本地的代码通过某些方式弄到线上,可以供别人访问 部署 前戏 ansible 批量在远程主机上执行命令 puppet ruby ansible saltstack pyt ...

  4. Ansible常用模块介绍及使用(week5_day1_part2)--技术流ken

    Ansible模块 在上一篇博客<Ansible基础认识及安装使用详解(一)--技术流ken>中以及简单的介绍了一下ansible的模块.ansible是基于模块工作的,所以我们必须掌握几 ...

  5. Ansible常用模块命令

    Ansible常用模块命令 一.安装ansible yum install epel-release yum install ansible 二.配置文件配置 vi /etc/ansible/ansi ...

  6. ansible 常用模块的使用

    安装 yum -y install ansible 配置文件/etc/ansible/hosts 模块介绍与使用 ping模块 [root@node1 config]# ansible k8s -m ...

  7. Ansible 常见模块介绍

    目录 Ansible 常见模块介绍 ping 模块 command 模块 cron 模块 user 模块 group 模块 copy 模块 file 模块 service 模块 shell 模块 sc ...

  8. Ansible 常用模块(一)

    一.Ansible简介 Ansible是新出现的自动化运维工具,基于python开发,集合了众多运维工具(puppet(ruby).cfengine.chef.func.fabric.)的优点,实现了 ...

  9. ansible核心模块playbook介绍

    ansible的playbook采用yaml语法,它简单地实现了json格式的事件描述.yaml之于json就像markdown之于html一样,极度简化了json的书写.在学习ansible pla ...

随机推荐

  1. python:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

    # 将默认编码设为utf-8 # 否则会报错: # UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ...

  2. js操作复选框 复选框

    //复选框点击事件 function checkAll(){ let tp=$("#tp").val(); let all=$("input[name='id']&quo ...

  3. 使用List中remove方法时需要注意的问题

    String str1 = new String("1"); String str2 = new String("2"); String str3 = new ...

  4. jquery实现select数据回显

    [html] view plain copy     <select class="div_select_re" id="edit_technicalGrade&q ...

  5. 动态查找之二叉树查找 c++实现

    算法思想 二叉搜索树(又称二叉查找树或二叉排序树)BST树 二叉查找树 二叉查找树,也称二叉搜索树,或二叉排序树.其定义也比较简单,要么是一颗空树,要么就是具有如下性质的二叉树: (1)若任意节点的左 ...

  6. 【深入学习linux】CentOS 7 最小化安装后程序必须安装的组件

    centos平台编译环境使用如下指令 安装make: yum -y install gcc automake autoconf libtool make 安装g++: yum install gcc ...

  7. JPA的动态查询拼接

    在使用Spring JPA提供的方法只能进行简单的CRUD,如果遇到复杂的情况就需要我们动态来构建查询条件了.这里我们来看使用CriteriaBuilder如何来构造查询.核心代码: Criteria ...

  8. android -------- VideoCache 视频播放(缓存视频到本地)

    先前做了一个小视频的功能,里面有播放多个视频的功能,为了效率,我加了视频缓存功能: 一方面耗费用户的流量,另一方面直接从本地播放要更流畅 网上看资料,一个视频缓存库,使用起来很方便,还不错,就分享给大 ...

  9. shell脚本:批量修改文件名(添加/删除文件名中字符)

    添加字符 举例如下:批量创建10个随机字符串的文件,要求每个文件名后面添加_aaa,后缀名不变: [root@localhost goodboy]# ls adddbbdedf.html  baacj ...

  10. tensorflow 笔记 15:如何使用 Supervisor

    如何使用Supervisor在不使用Supervisor的时候,我们的代码经常是这么组织的 variables ... ops ... summary_op ... merge_all_summari ...