提问人:Stranger 提问时间:11/13/2023 最后编辑:ZeitounatorStranger 更新时间:11/14/2023 访问量:35
根据 ec2 清单标签在撰写中选择ansible_user
Selecting ansible_user in compose based on a ec2 inventory tag
问:
我正在尝试获取分为两组标签和 的 ec2 主机列表,但根据包含用于连接到动态清单主机的主机的标签来确定 ansible_user 的值存在问题。tag_OS_ec2_user
tag_OS_ubuntu
以下是主机通过登录进行连接的条件,具体取决于主机是否包含在标记中:
ec2-inventory.yml:
plugin: aws_ec2
regions:
- eu-north-1
filters:
keyed_groups:
- prefix: region_is
key: placement.region
- prefix: arch
key: architecture
- prefix: tag
key: tags
compose:
ansible_user: "{{ 'ec2-user' if 'tag_OS_ec2_user' in tags else ('ubuntu' if 'tag_OS_ubuntu' in tags else '') }}"
库存输出:
"tag_OS_ec2_user": {
"hosts": [
"ec2-1-1-1-1.eu-north-1.compute.amazonaws.com",
"ec2-2-2-2-2.eu-north-1.compute.amazonaws.com"
]
},
"tag_OS_ubuntu": {
"hosts": [
"ec2-3-3-3-3.eu-north-1.compute.amazonaws.com",
"ec2-3-3-3-3.eu-north-1.compute.amazonaws.com"
]
但问题是,即使在传递 ansible_user:仅对于一个标签,ansible 也看不到 jinja 格式的字符串。当我通过时,只有 ssh 登录成功{{ 'ec2-user' }}
tag_OS_ec2_user
'ec2-user'
我想通过带有基于标签的 ssh 连接到主机
答: 暂无答案
评论
compose
ansible_user: "'ec2-user' if 'tag_OS_ec2_user' in tags else ('ubuntu' if 'tag_OS_ubuntu' in tags else '')"
tags
Inventory output