-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
825 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
- name: Initialize VMware and Deploy Cluster | ||
gather_facts: false | ||
hosts: localhost | ||
vars_files: | ||
vault.yaml | ||
tasks: | ||
- name: Create VMs | ||
vars: | ||
_vmware_assisted_installer_action: create | ||
ansible.builtin.include_role: | ||
name: vmware_assisted_installer | ||
|
||
- name: Create Cluster via Assisted API | ||
vars: | ||
_assisted_installer_action: create | ||
ansible.builtin.include_role: | ||
name: assisted_installer | ||
|
||
- name: Reconfigure and Boot VMs | ||
vars: | ||
_vmware_assisted_installer_action: boot | ||
ansible.builtin.include_role: | ||
name: vmware_assisted_installer | ||
|
||
- name: Wait for Hosts | ||
vars: | ||
_assisted_installer_action: host-wait | ||
ansible.builtin.include_role: | ||
name: assisted_installer | ||
|
||
- name: Assign Host Roles | ||
vars: | ||
_assisted_installer_action: host-role | ||
ansible.builtin.include_role: | ||
name: assisted_installer | ||
|
||
- name: Setup Storage | ||
vars: | ||
_assisted_installer_action: storage | ||
ansible.builtin.include_role: | ||
name: assisted_installer | ||
|
||
- name: Setup Networking | ||
vars: | ||
_assisted_installer_action: network | ||
ansible.builtin.include_role: | ||
name: assisted_installer | ||
|
||
- name: Start Installation | ||
vars: | ||
_assisted_installer_action: install | ||
ansible.builtin.include_role: | ||
name: assisted_installer | ||
|
||
- name: Wait for Install | ||
vars: | ||
_assisted_installer_action: install-wait | ||
ansible.builtin.include_role: | ||
name: assisted_installer | ||
|
||
- name: Save Credentials | ||
vars: | ||
_assisted_installer_action: credentials | ||
ansible.builtin.include_role: | ||
name: assisted_installer |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
- name: Initialize VMware and Deploy Cluster Nodes | ||
gather_facts: false | ||
hosts: localhost | ||
vars_files: | ||
vault.yaml | ||
tasks: | ||
- name: Clean up ~/.ssh/known_hosts | ||
when: | ||
- cleanup_known_hosts is defined | ||
- cleanup_known_hosts | ||
block: | ||
- name: Remove Lines w/ Inventory Hostname in known_hosts | ||
ansible.builtin.lineinfile: | ||
dest: ~/.ssh/known_hosts | ||
regexp: "^.*{{ item }}.{{ base_domain }}.*$" | ||
state: absent | ||
loop: "{{ groups[provision_group] }}" | ||
|
||
- name: Remove Lines w/ Inventory IP in known_hosts | ||
ansible.builtin.lineinfile: | ||
dest: ~/.ssh/known_hosts | ||
regexp: "^.*{{ lookup('dig', item) }}.*$" | ||
state: absent | ||
loop: "{{ groups[provision_group] }}" | ||
|
||
- name: Lookup infra-env-id | ||
ansible.builtin.set_fact: | ||
infra_env_id: "{{ lookup('ansible.builtin.file', artifact_directory + '/infra-env-id') }}" | ||
|
||
- name: Delete ISO From Download Path | ||
ansible.builtin.file: | ||
path: "{{ discovery_iso_download_path }}/{{ cluster_name }}-{{ infra_env_id }}-{{ discovery_iso_type }}.iso" | ||
state: absent | ||
|
||
- name: Delete Cluster from Red Hat Cloud Console | ||
vars: | ||
_assisted_installer_action: delete | ||
ansible.builtin.import_role: | ||
name: assisted_installer | ||
tags: | ||
- assisted-api | ||
|
||
- name: Retire VMs | ||
ansible.builtin.import_role: | ||
name: vmware_retire | ||
tags: | ||
- vmware | ||
|
||
- name: Delete ISO From Datastore | ||
community.vmware.vsphere_file: | ||
datacenter: "{{ vcenter_datacenter }}" | ||
datastore: "{{ discovery_iso_datastore }}" | ||
hostname: "{{ vcenter_hostname }}" | ||
password: "{{ vcenter_password }}" | ||
path: "{{ cluster_name }}-{{ infra_env_id }}-{{ discovery_iso_type }}.iso" | ||
username: "{{ vcenter_username }}" | ||
validate_certs: "{{ validate_certs }}" | ||
tags: | ||
- vmware |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ansible | ||
ansible-lint | ||
dnspython | ||
jmespath | ||
openshift | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
redhat_sso_url: https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token | ||
api_clusters_url: https://api.openshift.com/api/assisted-install/v2/clusters/ | ||
api_infra_envs_url: https://api.openshift.com/api/assisted-install/v2/infra-envs/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
- name: Query Clusters | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: GET | ||
status_code: 200 | ||
url: "{{ api_clusters_url }}" | ||
register: api_query_results | ||
|
||
- name: Create "cluster" Resource | ||
ansible.builtin.uri: | ||
body: | ||
name: "{{ cluster_name }}" | ||
high_availability_mode: "{{ high_availability_mode }}" | ||
openshift_version: "{{ openshift_y_release }}" | ||
pull_secret: '{{ pull_secret | from_json | to_json }}' | ||
base_dns_domain: "{{ base_dns_domain }}" | ||
cpu_architecture: "{{ cpu_architecture }}" | ||
disk_encryption: "{{ disk_encryption }}" | ||
body_format: json | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: POST | ||
status_code: 201 | ||
url: "{{ api_clusters_url }}" | ||
register: api_create_cluster_results | ||
|
||
- name: Set cluster_id Fact | ||
ansible.builtin.set_fact: | ||
cluster_id: "{{ api_create_cluster_results.json.id }}" | ||
|
||
- name: Debug cluster_id Fact | ||
ansible.builtin.debug: | ||
var: cluster_id | ||
|
||
- name: Write cluster_id to Artifact Directory | ||
ansible.builtin.copy: | ||
content: "{{ cluster_id }}" | ||
dest: "{{ artifact_directory }}/cluster-id" | ||
mode: "0644" | ||
|
||
- name: Create infra-env Resource | ||
ansible.builtin.uri: | ||
body: "{{ lookup('ansible.builtin.template', 'templates/infra-envs.j2') }}" | ||
body_format: json | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: POST | ||
status_code: 201 | ||
url: "{{ api_infra_envs_url }}" | ||
register: api_create_infra_envs_results | ||
|
||
- name: Debug infra_env_id | ||
ansible.builtin.debug: | ||
msg: "{{ api_create_infra_envs_results.json.id }}" | ||
|
||
- name: Write infra_env_id to Artifact Directory | ||
ansible.builtin.copy: | ||
content: "{{ api_create_infra_envs_results.json.id }}" | ||
dest: "{{ artifact_directory }}/infra-env-id" | ||
mode: "0644" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
- name: Query Cluster Credentials | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: GET | ||
status_code: 200 | ||
url: "{{ api_clusters_url + cluster_id }}/credentials" | ||
register: api_query_credentials_results | ||
|
||
- name: Write Credentials to Artifact Directory | ||
vars: | ||
_console_password: "{{ api_query_credentials_results.json.password }}" | ||
_console_url: "{{ api_query_credentials_results.json.console_url }}" | ||
_console_username: "{{ api_query_credentials_results.json.username }}" | ||
ansible.builtin.copy: | ||
content: "{{ lookup('ansible.builtin.template', 'templates/credentials.j2') }}" | ||
dest: "{{ artifact_directory }}/credentials" | ||
mode: "0600" | ||
|
||
- name: Query kubeconfig URL | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: GET | ||
status_code: 200 | ||
url: "{{ api_clusters_url + cluster_id }}/downloads/credentials-presigned?file_name=kubeconfig" | ||
register: api_query_kubeconfig_url_results | ||
|
||
- name: Download kubeconfig | ||
ansible.builtin.get_url: | ||
dest: "{{ artifact_directory }}/kubeconfig" | ||
url: "{{ api_query_kubeconfig_url_results.json.url }}" | ||
mode: "0600" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- name: Delete "cluster" Resource | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: DELETE | ||
status_code: 204 | ||
url: "{{ api_clusters_url }}/{{ lookup('ansible.builtin.file', artifact_directory + '/cluster-id') }}" | ||
register: api_create_cluster_results |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- name: Set Host Role | ||
ansible.builtin.uri: | ||
body: | ||
host_role: "{{ hostvars[item.host].api_node_type }}" | ||
body_format: json | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: PATCH | ||
status_code: 201 | ||
url: "{{ api_infra_envs_url + api_create_infra_envs_results.json.id }}/hosts/{{ item.id }}" | ||
loop: "{{ _assisted_host_info }}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
- name: Query Clusters | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: GET | ||
status_code: 200 | ||
url: "{{ api_clusters_url }}" | ||
register: api_query_results | ||
|
||
- name: Set Expected Host Count | ||
ansible.builtin.set_fact: | ||
_inventory_host_count: "{{ groups[provision_group] | count }}" | ||
|
||
- name: Query Hosts | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: GET | ||
status_code: 200 | ||
url: "{{ api_infra_envs_url + api_create_infra_envs_results.json.id }}/hosts" | ||
delay: 10 | ||
register: api_query_hosts_results | ||
retries: 180 | ||
until: | ||
- api_query_hosts_results.json is defined | ||
- (api_query_hosts_results.json | count) == (_inventory_host_count | int) | ||
- (api_query_hosts_results.json | json_query(_query_simple_status) | count) == (_inventory_host_count | int) | ||
vars: | ||
_query_simple_status: "[?status=='pending-for-input' || status=='known' || status=='installed']" | ||
|
||
- name: Combine Applicable Host Properties into Dictionary for Easy Lookup | ||
ansible.builtin.set_fact: | ||
_assisted_host_info: >- | ||
{{ | ||
_assisted_host_info | default([]) + | ||
[ | ||
{ | ||
'host': item.requested_hostname | split('.') | first, | ||
'id': item.id, | ||
'inventory': item.inventory | from_json, | ||
'status': item.status, | ||
'status_info': item.status_info, | ||
'validations_info': item.validations_info | from_json | ||
} | ||
] | ||
}} | ||
loop: "{{ api_query_hosts_results.json }}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
- name: Query Hosts | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: GET | ||
status_code: 200 | ||
url: "{{ api_infra_envs_url + api_create_infra_envs_results.json.id }}/hosts" | ||
register: api_query_hosts_results | ||
|
||
- name: Reset Variable | ||
ansible.builtin.set_fact: | ||
_assisted_host_info: [] | ||
|
||
- name: Combine Applicable Host Properties into Dictionary for Easy Lookup | ||
ansible.builtin.set_fact: | ||
_assisted_host_info: >- | ||
{{ | ||
_assisted_host_info + | ||
[ | ||
{ | ||
'host': item.requested_hostname | split('.') | first, | ||
'id': item.id, | ||
'inventory': item.inventory | from_json, | ||
'status': item.status, | ||
'status_info': item.status_info, | ||
'validations_info': item.validations_info | from_json | ||
} | ||
] | ||
}} | ||
loop: "{{ api_query_hosts_results.json }}" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
- name: Wait for Cluster to Finish Installation | ||
block: | ||
- name: Generate Access Token | ||
ansible.builtin.uri: | ||
body: | ||
client_id: rhsm-api | ||
grant_type: refresh_token | ||
refresh_token: "{{ offline_token }}" | ||
body_format: form-urlencoded | ||
method: POST | ||
url: "{{ redhat_sso_url }}" | ||
register: access_token | ||
|
||
- name: Query Cluster Status | ||
ansible.builtin.uri: | ||
headers: | ||
Authorization: "Bearer {{ access_token.json.access_token }}" | ||
method: GET | ||
status_code: 200 | ||
url: "{{ api_clusters_url + cluster_id }}" | ||
delay: 10 | ||
register: api_query_cluster_results | ||
retries: 180 | ||
until: | ||
- api_query_cluster_results.json is defined | ||
- api_query_cluster_results.json.status is defined | ||
- api_query_cluster_results.json.status == "installed" | ||
rescue: | ||
- name: Debug access_token | ||
ansible.builtin.debug: | ||
var: access_token | ||
|
||
- name: Debug api_query_cluster_results | ||
ansible.builtin.debug: | ||
var: api_query_cluster_results | ||
|
||
- name: Retry Infinitely | ||
ansible.builtin.include_tasks: | ||
file: install-wait.yaml |
Oops, something went wrong.