当前位置:网站首页>【漏网之鱼】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
边栏推荐
猜你喜欢

js中entries(),keys(),values() , some(), Object.assign()遍历数组用法

LeetCode刷题|368最大整除子集(动态规划)

Kids and COVID: why young immune systems are still on top

TP5 error reporting variable type error: array solution

修改Jupyter Notebook样式

Leak detection and vacancy filling (III)

1-1 NodeJS

ubuntu下搭建mysql环境 & 初识SQL

批量修改/批量更新数据库某一个字段的值

tp5 报错variable type error: array解决方法
随机推荐
A website that directly downloads PNG icons without logging in
Offset et client pour obtenir des informations sur l'emplacement des éléments Dom
Decentralized Collaborative Learning Framework for Next POI Recommendation
mysql中sum (if)_mysql 中sum (if())
Leak detection and vacancy filling (IV)
Leetcode刷题之实现strStr()
DNA reveals surprise ancestry of mysterious Chinese mummies
EF CORE在ASP.NET CORE项目中基于数据库优先模式生成实体模型
TP5 uses redis
SQL学习|集合运算
JS regular matching first assertion and last assertion
The arithmetic square root of X in leetcode
Leak detection and vacancy filling (IX) -- Procedure
tc ebpf 实践
虚拟环境中使用jupyter notebook
TP5 error reporting variable type error: array solution
阅读笔记:Secure Federated Matrix Factorization
Typescript (top)
【代码解析(2)】Communication-Efficient Learning of Deep Networks from Decentralized Data
Your brain expands and shrinks over time — these charts show how