This post describes how to perform VCF bringup via Ansible. If you need another VCF related ansible playbooks check rest of my blog posts in here.
Backing to VCF bringup, my folder structure is as follow:
startVcfBringup.yml
/roles/
/runVcfBringup/
/defaults/
main.yml
/tasks/
main.yml
validateVcfBringup.yml
startVcfBringup.yml
startVcfBringup.yml playbook
# Playbook performs validation and deployment of SDDC via CloudBuilder API
---
- name: Start VCF bringup
hosts: localhost
gather_facts: false
vars_files:
- group_vars/myVars
tasks:
- name: Import role runVcfBringup
include_role:
name: runVcfBringup
/roles/runVcfBringup/defaults/main.yml
- cloudBuilderRestApiSddcValidate – var for Cloud Builder API used for input specification validation.
- cloudBuilderRestApiSddcCreate: var for Cloud Builder API used triggering the task using the valid input specification.
- bringupJsonPath – var for location on my ansible host where Deployment Parameter Workbook file converted to json is located (input specification).
---
# defaults file for runVcfBringup
cloudBuilderRestApiSddcValidate: "https://{{ CloudBuilderFQDN }}/v1/sddcs/validations"
cloudBuilderRestApiSddcCreate: "https://{{ CloudBuilderFQDN }}/v1/sddcs"
bringupJsonPath: "/home/admin/vcfBringup.json"
cbAdminUser: "admin"
cbAdminUserPassword: "P@ssw0rd"
/roles/runVcfBringup/tasks/main.yml
---
- name: Validate JSON input for VCF bring up
import_tasks: validateVcfBringup.yml
- name: Create VCF bringup basing on JSON input
import_tasks: startVcfBringup.yml
/roles/runVcfBringup/tasks/validateVcfBringup.yml
---
#validateVcfBringup.yml
- name: Trigger VCF parameter Workbook JSON input validation
uri:
url: "{{ cloudBuilderRestApiSddcValidate }}"
method: POST
user: "{{ cbAdminUser }}"
password: "{{ cbAdminUserPassword }}"
validate_certs: no
force_basic_auth: yes
return_content: yes
body_format: json
body: "{{ lookup('file','{{ bringupJsonPath }}') }}"
status_code: 200,202
register: vcfBringupValidation
- name: Register validation task ID
set_fact:
validationId: "{{ vcfBringupValidation.json.id }}"
- name: Get validation status
uri:
url: "{{ cloudBuilderRestApiSddcValidate }}/{{ validationId }}"
method: GET
user: "{{ cbAdminUser }}"
password: "{{ cbAdminUserPassword }}"
validate_certs: no
force_basic_auth: yes
return_content: yes
body_format: json
register: vcfBringupValidationQuery
until: (vcfBringupValidationQuery.json.resultStatus | lower == 'succeeded') or (vcfBringupValidationQuery.json.resultStatus | lower == 'failed')
delay: 30
retries: 200
- name: Show validation report
debug:
var: vcfBringupValidationQuery
verbosity: 1
- name: Error message if validation failed
fail:
msg:
- "Validation failed. Failed steps have to be fixed before continue."
when: vcfBringupValidationQuery.json.resultStatus | lower == 'failed'
- name: No error message if validation is successful
debug:
msg: "Validation successful. Proceeding with VCF bring up."
when: vcfBringupValidationQuery.json.resultStatus | lower == 'succeeded'
/roles/runVcfBringup/tasks/startVcfBringup.yml
---
#startVcfBringup.yml
- name: Start VCF bring-up process
uri:
url: "{{ cloudBuilderRestApiSddcCreate }}"
method: POST
user: "{{ cbAdminUser }}"
password: "{{ cbAdminUserPassword }}"
validate_certs: no
force_basic_auth: yes
return_content: yes
body_format: json
body: "{{ lookup('file','{{ bringupJsonPath }}') }}"
status_code: 200,202
register: vcfBringupCreation
- name: Register creation task ID
set_fact:
taskId: "{{ vcfBringupCreation.json.id }}"
- name: Get creation task status
uri:
url: "{{ cloudBuilderRestApiSddcCreate }}/{{ taskId }}"
method: GET
user: "{{ cbAdminUser }}"
password: "{{ cbAdminUserPassword }}"
validate_certs: no
force_basic_auth: yes
return_content: yes
body_format: json
register: vcfBringupCreationTask
until: (vcfBringupCreationTask.json.status | lower == 'completed_with_success') or (vcfBringupCreationTask.json.status | lower == 'completed_with_failure')
delay: 60
retries: 200
- name: Show creation report
debug:
var: vcfBringupCreationTask
verbosity: 1
- name: Error message if creation failed
fail:
msg:
- "VCF bring up failed. Failed steps have to be fixed before continue. Task have to be retried. Task ID: {{ taskId }}"
when: vcfBringupCreationTask.json.status | lower == 'completed_with_failure'
- name: No error message if creation is successful
debug:
msg: "VCF bring up performed successfully."
when: vcfBringupCreationTask.json.status | lower == 'completed_with_success'