在搞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)