当前位置:网站首页>ansible模块之include_tasks:为什么加了tags后导入的任务没有执行?
ansible模块之include_tasks:为什么加了tags后导入的任务没有执行?
2022-04-23 05:59:00 【Sebastien23】
本文中ansible的版本为2.9。
场景再现
下面是Role中的要测试的任务:
# role01.yml
# ...前面的tasks
- name: included task for test
include_tasks: test01.yml
tags:
- test01
# ... 后面的tasks
在执行整个Role时,test01.yml会被正常导入playbook并执行:
$ ansible-playbook -i hosts.ini all role01.yml
但是当我们想通过tags单独测试这个任务时,
$ ansible-playbook -i hosts.ini all role01.yml --tags "test01"
奇怪的事情发生了:include_tasks本身这个任务执行成功了,但是被导入的test01.yml却并没有被执行!
原因分析
在对include_tasks任务使用tags时,只会对include_tasks任务本身生效,而并不会对其中包含的任务生效。
那如果我们要对其中包含的任务也生效,该怎么做呢?
解决办法
可以通过include_tasks模块的apply参数,为包含的任务添加标签。
将上面的任务改成下面的形式
# role01.yml
# ...前面的tasks
- name: included task for test
include_tasks:
file: test01.yml
apply:
tags: test01
tags: always
# ... 后面的tasks
然后调用即可:
$ ansible-playbook -i hosts.ini all role01.yml --tags "test01"
注意,上面的 tags: always 不能省略,否则 include_tasks本身不会被执行。always标签只对include_tasks本身生效。在调用其他tags时,include_tasks也会always执行,但是其中包含的任务不会被执行。
版权声明
本文为[Sebastien23]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Sebastien23/article/details/122648720
边栏推荐
猜你喜欢
随机推荐
Baidu map coordinates, Google coordinates and Tencent coordinates are mutually transformed
百度地图坐标、Google坐标、腾讯坐标相互转化
China creates vast research infrastructure to support ambitious climate goals
freeCodeCamp----arithmetic_arranger练习
Leak detection and filling (I)
PHP background parsing after JQ serialization
file_get_contents 访问 ssl 错误的两种解决方法
SQL学习|窗口函数
DNA reveals surprise ancestry of mysterious Chinese mummies
input文件上传
JS performance optimization
Leetcode刷题之实现strStr()
浏览器中堆栈内存的底层处理
Kids and COVID: why young immune systems are still on top
不用登录直接下载PNG图标的一个网站
DDOS攻击/防御介绍
Leak detection and vacancy filling (IX) -- Procedure
1-1 NodeJS
ovs与ovs+dpdk架构分析
Tensorflow&&Pytorch常见报错









