Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ansible - Make conversion host record creation idempotent #25

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
---
- include_tasks: "install-manageiq-build-conversion-host-resource-{{ v2v_host_type }}.yml"

- uri:
url: "{{ manageiq_url }}/api/conversion_hosts"
user: "{{ manageiq_username }}"
password: "{{ manageiq_password }}"
method: "POST"
validate_certs: "{{ manageiq_validate_certs | default(true) }}"
body_format: "json"
body:
action: "create"
resource: "{{ manageiq_post_conversion_host_resource }}"
when:
- "manageiq_post_conversion_host_resource is defined"

- block:
- set_fact:
manageiq_conversion_host_resource_tags:
- category: "v2v_transformation_host"
name: "true"

- set_fact:
manageiq_tag_vddk_transport:
- category: "v2v_transformation_method"
name: "vddk"

- set_fact:
manageiq_tag_ssh_transport:
- category: "v2v_transformation_method"
name: "ssh"

- set_fact:
manageiq_conversion_host_resource_tags: "{{ manageiq_conversion_host_resource_tags }} + {{ manageiq_tag_vddk_transport }}"
when:
- "'vddk' in v2v_transport_methods"

- set_fact:
manageiq_conversion_host_resource_tags: "{{ manageiq_conversion_host_resource_tags }} + {{ manageiq_tag_ssh_transport }}"
when:
- "'ssh' in v2v_transport_methods"

- name: Tag as conversion host
- include_tasks: "install-manageiq-remove-existing-conversion-host.yml"

- name: Create the conversion host record
uri:
url: "{{ manageiq_post_conversion_host_resource_href }}/tags"
url: "{{ manageiq_url }}/api/conversion_hosts"
user: "{{ manageiq_username }}"
password: "{{ manageiq_password }}"
method: "POST"
validate_certs: "{{ manageiq_validate_certs | default(true) }}"
body_format: "json"
body:
action: "assign"
resources: "{{ manageiq_conversion_host_resource_tags }}"
action: "create"
resource: "{{ manageiq_post_conversion_host_resource }}"

- block:
- set_fact:
manageiq_conversion_host_resource_tags:
- category: "v2v_transformation_host"
name: "true"

- set_fact:
manageiq_tag_vddk_transport:
- category: "v2v_transformation_method"
name: "vddk"

- set_fact:
manageiq_tag_ssh_transport:
- category: "v2v_transformation_method"
name: "ssh"

- set_fact:
manageiq_conversion_host_resource_tags: "{{ manageiq_conversion_host_resource_tags }} + {{ manageiq_tag_vddk_transport }}"
when:
- "'vddk' in v2v_transport_methods"

- set_fact:
manageiq_conversion_host_resource_tags: "{{ manageiq_conversion_host_resource_tags }} + {{ manageiq_tag_ssh_transport }}"
when:
- "'ssh' in v2v_transport_methods"

- name: Tag as conversion host
uri:
url: "{{ manageiq_post_conversion_host_resource_href }}/tags"
user: "{{ manageiq_username }}"
password: "{{ manageiq_password }}"
method: "POST"
validate_certs: "{{ manageiq_validate_certs | default(true) }}"
body_format: "json"
body:
action: "assign"
resources: "{{ manageiq_conversion_host_resource_tags }}"

when:
- "manageiq_post_conversion_host_resource_href is defined"

when:
- "manageiq_post_conversion_host_resource_href is defined"
- "manageiq_post_conversion_host_resource is defined"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Identify conversion hosts with same name
uri:
url: "{{ manageiq_url }}/api/conversion_hosts?expand=resources&attributes=resource&filter[]=name={{ manageiq_post_conversion_host_resource.name }}"
user: "{{ manageiq_username }}"
password: "{{ manageiq_password }}"
method: "GET"
validate_certs: "{{ manageiq_validate_certs | default(true) }}"
register: manageiq_conversion_hosts_json

- block:
- name: Isolate the relevant conversion host
set_fact:
manageiq_existing_conversion_host: "{{ manageiq_conversion_hosts_json.json | json_query('resources[*]') | first }}"

- name: Delete the existing conversion host record
uri:
url: "{{ manageiq_existing_conversion_host.href }}"
user: "{{ manageiq_username }}"
password: "{{ manageiq_password }}"
method: "DELETE"
validate_certs: "{{ manageiq_validate_certs | default(true) }}"
status_code: 204

when:
- "manageiq_conversion_hosts_json.json.subcount != 0"