我有一个简单的Ansible角色,它创建一个Foreman激活键,但是它只具有最后一个值的“订阅”,而不是两者都有?
# cat roles/hammer/tasks/subscription.yml
---
- name: Add Subscription key ID to Activation Key
katello_activation_key:
username: "{{ hammer.username|default('NotSet') }}"
password: "{{ hammer.password|default('NotSet') }}"
server_url: "https://{{ system_host_name }}"
name: "{{ item.0.name }}"
organization: "{{ hammer.organisation.name }}"
lifecycle_environment: "{{ item.0.lifecycle }}"
content_view: '{{ item.0.cview }}'
subscriptions:
- name: "{{ item.1 }}"
# - name: "{{ item.1.name2 }}"
auto_attach: False
release_version: Initial
tags: hammer
...我的vars文件包含:
act_key:
- name: CentOS 7 content Development Key
desc: CentOS 7 content Development Key
release: Initial
cview: CentOS 7 content
lifecycle: Development
# subscription: ['CentOS-7','CentOS-7-EPEL']
subscription:
- CentOS-7
- CentOS-7-EPEL
- name: CentOS 7 content Production Key
desc: CentOS 7 content Production Key
cview: CentOS 7 content
release: Initial
lifecycle: Production
# subscription: ['CentOS-7','CentOS-7-EPEL']
subscription:
- CentOS-7
- CentOS-7-EPEL
- name: CentOS 8 content Development Key
desc: CentOS 8 content Development Key
cview: CentOS 8 content
release: Initial
lifecycle: Development
# subscription: ['CentOS-8','CentOS-8-EPEL']
subscription:
- CentOS-8
- CentOS-8-EPEL
- name: CentOS 8 content Production Key
desc: CentOS 8 content Production Key
cview: CentOS 8 content
release: Initial
lifecycle: Production
# subscription: ['CentOS-8','CentOS-8-EPEL']
subscription:
- CentOS-8
- CentOS-8-EPEL我试图在一次传递中添加““CentOS-7”、“CentOS-7-EPEL”:with_subelements”,就像我使用"with_subelements“循环一样--只添加最后一项”CentOS7-Epel“或"CentOS-8-EPEL”(而不是两者兼而有之)。
有人能建议改变我的变量文件或播放使katello_activation_key在一次传递中添加两个变量的方法吗?
发布于 2021-02-15 14:52:55
首先,act_key中的字典列表包含一个键subscription,该值是一个列表。所以你不需要在多个列表上迭代
- name: Add Subscription key ID to Activation Key
katello_activation_key:
..
name: "{{ item.name }}"
organization: "{{ hammer.organisation.name }}"
lifecycle_environment: "{{ item.lifecycle }}"
content_view: '{{ item.cview }}'
subscriptions: "{{ item.subscription }}"
...
loop: "{{ act_key }}"第二,katello_activation_key.subscriptions不允许字符串列表(但也不允许单键name的dict列表),因此您可以使用字典或items2dict创建名称列表的映射/dict。但是,为了更好地阅读,我更倾向于更改act_key,以便在订阅中包含相同的格式,这样´katello_activation_key`就需要。
https://serverfault.com/questions/1053667
复制相似问题