Last active
May 28, 2021 11:23
-
-
Save natefoo/6fd55573478a38b50e359505495ed0cf to your computer and use it in GitHub Desktop.
Ansible tasks for selecting an OpenStack image from a list using a regular expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Get Image | |
hosts: all | |
gather_facts: no | |
environment: | |
OS_CLOUD: "{{ cloud_id }}" | |
OS_IDENTITY_API_VERSION: '3' | |
connection: local | |
tasks: | |
- name: Collect image facts | |
os_image_facts: | |
delegate_to: localhost | |
- name: Display image facts | |
debug: | |
msg: "{% if item.name.startswith('JS-API-Featured-CentOS7-') %}{% set image = item.id %}{% endif %}" | |
with_items: "{{ openstack_image }}" | |
no_log: true | |
- name: Debug image | |
debug: | |
var: image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Get Image | |
hosts: all | |
gather_facts: no | |
environment: | |
OS_CLOUD: "{{ cloud_id }}" | |
OS_IDENTITY_API_VERSION: '3' | |
connection: local | |
tasks: | |
- name: Collect image facts | |
os_image_facts: | |
delegate_to: localhost | |
- name: Find current JS-API-Featured-CentOS7 image | |
set_fact: | |
image: "{{ item }}" | |
with_items: "{{ openstack_image }}" | |
when: item.name.startswith('JS-API-Featured-CentOS7-') | |
loop_control: | |
label: item.name | |
- name: Debug image | |
debug: | |
var: image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Get Image | |
hosts: all | |
gather_facts: no | |
environment: | |
OS_CLOUD: "{{ cloud_id }}" | |
OS_IDENTITY_API_VERSION: '3' | |
connection: local | |
tasks: | |
- name: Collect image facts | |
os_image_facts: | |
delegate_to: localhost | |
- name: Find current JS-API-Featured-CentOS7 image | |
set_fact: | |
image: "{{ ( openstack_image | selectattr('name', 'match', '(?i)^JS-API-Featured-CentOS7-[A-Z]{3}-\\d{1,2}-\\d{4}$') | list | last ).id }}" | |
run_once: true | |
- name: Debug image | |
debug: | |
var: image |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment