Skip to content

Commit

Permalink
restructure resource pool creation to avoid code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Knappek committed Dec 4, 2024
1 parent b6b1d0b commit 44bee58
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 33 deletions.
16 changes: 8 additions & 8 deletions roles/tanzu/opsman/configure-bosh/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
---
- name: Create BOSH AZ resource pool
community.vmware.vmware_resource_pool:
hostname: "{{ bosh_vcenter_url }}"
username: "{{ bosh_vcenter_username }}"
password: "{{ bosh_vcenter_password }}"
validate_certs: false
ansible.builtin.include_role:
name: vsphere/vsphere-resource-pool
vars:
vcenter_ip: "{{ bosh_vcenter_url }}"
vcenter_username: "{{ bosh_vcenter_username }}"
vcenter_password: "{{ bosh_vcenter_password }}"
datacenter: "{{ bosh_vcenter_datacenter }}"
cluster: "{{ bosh_vcenter_cluster }}"
cluster_name: "{{ bosh_vcenter_cluster }}"
resource_pool: "{{ bosh_az_resource_pool }}"
state: present
delegate_to: localhost
when: bosh_az_resource_pool != ""


- name: Fetch NSX Manager cert
ansible.builtin.shell: |
set -o pipefail && \
Expand Down
16 changes: 8 additions & 8 deletions roles/tanzu/opsman/install-opsman/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
opsman_env: |
{{ lookup('template', 'env.yml') | from_yaml }}
- name: Create resource pool
community.vmware.vmware_resource_pool:
hostname: "{{ opsman_vcenter_url }}"
username: "{{ opsman_vcenter_username }}"
password: "{{ opsman_vcenter_password }}"
validate_certs: false
- name: Create resource pool for Opsman
ansible.builtin.include_role:
name: vsphere/vsphere-resource-pool
vars:
vcenter_ip: "{{ opsman_vcenter_url }}"
vcenter_username: "{{ opsman_vcenter_username }}"
vcenter_password: "{{ opsman_vcenter_password }}"
datacenter: "{{ opsman_vcenter_datacenter }}"
cluster: "{{ opsman_vcenter_cluster }}"
cluster_name: "{{ opsman_vcenter_cluster }}"
resource_pool: "{{ opsman_vcenter_resource_pool }}"
state: present
when: opsman_vcenter_resource_pool != "Resources"

- name: Deploy Opsman VM
Expand Down
16 changes: 8 additions & 8 deletions roles/ubuntu-server/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
- name: Create resource pool
community.vmware.vmware_resource_pool:
hostname: "{{ vcsa_hostname }}"
username: "{{ vcsa_username }}"
password: "{{ vcsa_password }}"
validate_certs: false
- name: Create resource pool for Ubuntu VM
ansible.builtin.include_role:
name: vsphere/vsphere-resource-pool
vars:
vcenter_ip: "{{ vcsa_hostname }}"
vcenter_username: "{{ vcsa_username }}"
vcenter_password: "{{ vcsa_password }}"
datacenter: "{{ datacenter }}"
cluster: "{{ cluster }}"
cluster_name: "{{ cluster }}"
resource_pool: "{{ vm_resource_pool }}"
state: present
when: vm_resource_pool is defined

- name: Deploy Ubuntu OVA
Expand Down
12 changes: 12 additions & 0 deletions roles/vsphere/vsphere-resource-pool/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Add resource pool to vCenter
community.vmware.vmware_resource_pool:
hostname: "{{ vcenter_ip }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
datacenter: "{{ datacenter }}"
cluster: "{{ cluster_name }}"
resource_pool: "{{ resource_pool }}"
state: present
delegate_to: localhost
17 changes: 8 additions & 9 deletions roles/vsphere/vsphere-resource-pools/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
{% endfor %}
]
- name: Add resource pool to vCenter
community.vmware.vmware_resource_pool:
hostname: "{{ nested_vcenter.ip }}"
username: "{{ nested_vcenter.username }}"
password: "{{ nested_vcenter.password }}"
validate_certs: false
- name: Add resource pools to vCenter
ansible.builtin.include_role:
name: vsphere/vsphere-resource-pool
vars:
vcenter_ip: "{{ nested_vcenter.ip }}"
vcenter_username: "{{ nested_vcenter.username }}"
vcenter_password: "{{ nested_vcenter.password }}"
datacenter: "{{ nested_vcenter.datacenter }}"
cluster: "{{ item.cluster_name }}"
cluster_name: "{{ item.cluster_name }}"
resource_pool: "{{ item.resource_pool }}"
state: present
loop: "{{ resource_pools_to_add }}"
delegate_to: localhost

0 comments on commit 44bee58

Please sign in to comment.