当前位置:网站首页>【漏网之鱼】Ansible AWX调用playbook传参问题
【漏网之鱼】Ansible AWX调用playbook传参问题
2022-04-23 05:59:00 【Sebastien23】
【漏网之鱼】Ansible AWX调用playbook传参问题
问题背景
通过ansible AWX使用Web接口调用playbook时,出现了playbook在运行时无法读取某些变量、以及读取到的某些变量与定义的值不同的情况。Playbook的结构如下:
my-test-playbook
|--ansible.cfg
|--fact_files
|--group_vars
|--all.yml
|--deploy.yml
|--inventory.ini
|--log
|--ansible.log
|--README
|--retry_files
|--roles
|--rolePremiere
|--defaults
|--main.yml
|--tasks
|--main.yml
|--files
|--templates
|--app.conf.j2
|--vars
|--roleSecond
|--roleThird
|--rollback.yml
|--start.yml
|--stop.yml
问题一:读不到inventory.ini中的变量
在inventory.ini
中定义如下内容:
[appNode]
192.168.x.A ansible_ssh_port=xxx ansible_ssh_user=root
192.168.y.B ansible_ssh_port=xxx ansible_ssh_user=root
[all:vars]
major_version = 5
basedir = /opt/app
is_cluster = true
is_consistent = false
在执行roles/rolePremiere/tasks/main.yml
中的相关任务时,在使用inventory.ini中[all:vars]
下定义的变量时,竟然提示该变量未定义!但是[appNode]
中的hosts信息可以读到。
奇怪的是,当我把这些变量移动到group_vars/all.yml
或者是对应role下的defaults/main.yml
中后,就可以读取到相应的变量了!
问题二:读到的变量与定义值不同
我在roles/rolePremiere/templates/app.conf.j2
中使用到了变量is_consistent
作为判断的条件,如下
{
% if ( is_consistent == "false" ) %}
根据上面定义的值(假设该变量定义在group_vars/all.yml
中),这个判断条件应该成立。但事实上,if后面对应的语句却并没有执行。
通过检查日志和目标机器上的文件发现,在调用该模板文件时,该变量的值变成了False
,即首字母变成了大写,导致判断条件不成立。
绕行的办法是改写上面的判断语句为
{
% if ( is_consistent | string | lower == "false" ) %}
版权声明
本文为[Sebastien23]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Sebastien23/article/details/123237032
边栏推荐
- LeetCode刷题|368最大整除子集(动态规划)
- Counts the number of occurrences of each character in the string
- sql中的 IF 条件语句的用法
- 不用登录直接下载PNG图标的一个网站
- JS regular matching first assertion and last assertion
- Implementation of leetcode question brushing str ()
- el-cascader和el-select点击别处让下拉框消失
- LeetCode刷题|13罗马数字转整数
- file_get_contents 访问 ssl 错误的两种解决方法
- JS handwriting compatibility event binding
猜你喜欢
rdma网络介绍
Leak detection and vacancy filling (II)
LeetCode刷题|368最大整除子集(动态规划)
TP5 uses redis
Binary sum of leetcode questions
Decentralized Collaborative Learning Framework for Next POI Recommendation
ovs与ovs+dpdk架构分析
.NET类型转移
LeetCode刷题|两个链表的第一个公共节点
阅读笔记:Meta Matrix Factorization for Federated Rating Predictions
随机推荐
rdam 原理解析
fdfs启动
Get DOM element location information by offset and client
bcc安装和基本工具使用说明
JS实现模态框拖拽
Leak detection and filling (I)
Method of MySQL password expiration
Mailbox string judgment
Leetcode integer plus one
ovs与ovs+dpdk架构分析
百度地图案例-修改地图样式
Leak detection and vacancy filling (IX) -- Procedure
Counts the number of occurrences of each character in the string
2021-09-18
mysql密码过期的方法
修改Jupyter Notebook样式
【代码解析(1)】Communication-Efficient Learning of Deep Networks from Decentralized Data
百度地图基础案例
JS性能优化
DNA reveals surprise ancestry of mysterious Chinese mummies