如何根据变量或事实过滤ansible列表?假设我有一个列表,其中列出了我想要的软件包和名称片段。
vars:
package_urls: ['http...windows.exe', 'http...linux.rpm', 'http...babbage.steam']
package_name: 'linux'
tasks:
- set_fact:
selected_url: "{{ package_urls | select( 'match', '.*' + package_name + '.*') |list| first}}"
- debug:
msg: "Select for {{ package_name }} is {{ selected_url }}"
这会产生所需的输出,但是肯定看起来很麻烦
Select for linux is http...linux.rpm