ansible - 连接到另一台主机时,ansible 不会读入变量
问题描述
我有一本剧本,其中读入了变量列表:
vars_files:
- vars/myvariables.yml
tasks:
- name: Debug Variable List
debug:
msg: "An item: {{item}}"
with_list: "{{ myvariables }}"
这会从文件 variables.yml 中打印出“myvariables”列表,其中包含:
---
myvariables:
- variable1
- variable2
我按预期得到以下内容。
"msg": "An item: variable1"
"msg": "An item: variable2"
但是,当我连接到另一台主机并运行相同的 Debug 语句时,它会引发错误:
vars_files:
- vars/myvariables.yml
tasks:
- name: Configure instance(s)
hosts: launched
become: True
remote_user: ubuntu
port: 22
gather_facts: False
tasks:
- name: Wait for SSH to come up
delegate_to: ***
remote_user: ubuntu
connection: ssh
register: item
- name: Debug Variable List
debug:
msg: "An item: {{item}}"
with_list: "{{ myvariables }}"
输出:
"msg": "'myvariables' is undefined"
连接到非本地主机的另一台主机时如何定义变量文件?
对此的任何帮助将不胜感激。
解决方案
随着“ hosts:launched ”你开始了新的剧本。将vars_files:放入本剧本的范围内(见下文)。
- name: Configure instance(s)
hosts: launched
become: True
remote_user: ubuntu
port: 22
gather_facts: False
vars_files:
- vars/myvariables.yml
tasks:
查看范围变量。
推荐阅读
- azure-machine-learning-studio - Azure AutoML 似乎添加了额外的输入?
- sql - 检查以前记录的值后更新记录
- wordpress - 将单个 wordpress 页面绑定到单个端点
- c# - 将 JSON 反序列化为自定义 c# 对象列表
- javascript - 单击链接打开一个新页面,然后打开手风琴并滚动到带有 ID 的部分
- python - 使用 [None].T 生成的 Python Numpy 数组
- r - 鱿鱼游戏第 7 集与模拟
- c++ - QAbstractTableModel 和 QSortFilterProxyModel - 如何清除数据和更新视图
- r - R:根据值的彩色矩阵
- azure - 使用 pyspark 在 azure synapse studio 中获取文件的完整路径