-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'internal/main'
- Loading branch information
Showing
91 changed files
with
6,393 additions
and
316 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
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 |
---|---|---|
|
@@ -34,3 +34,4 @@ tfxjs.tfvars | |
tf-test/ | ||
dev/ | ||
|
||
vars.yml |
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
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,138 @@ | ||
--- | ||
# To setup this directory to run locally, copy /vars/vars.template.yml to /vars/vars.yml and fill in needed | ||
# values | ||
# To run the playbook locally, run `ansible-playbook main.yml` in this directory. | ||
# This playbook creates a schematics workspace, uploads a craig .tar file for a specific template to | ||
# that workspace, generates a plan, applies the plan to create the resources in the template, and destroys | ||
# the newly created resources. | ||
# If any step fails, the playbook will stop and print the error to the terminal. | ||
|
||
- name: Upload CRAIG template to schematics workspace | ||
hosts: localhost | ||
vars_files: ./vars/vars.yml | ||
- name: Get IAM token | ||
hosts: localhost | ||
vars_files: ./vars/vars.yml # variables declared in variables file are added to role automatically | ||
roles: | ||
- role: get_iam_token | ||
- name: "Download Template Tarball" | ||
hosts: localhost | ||
vars_files: ./vars/vars.yml | ||
tasks: | ||
- name: Download {{template}}.tar to current directory | ||
get_url: | ||
url: "{{craig_url}}/{{template}}" | ||
dest: "{{playbook_dir}}/{{template}}.tar" | ||
async: 120 | ||
retries: 10 | ||
- name: Create Schematics Workspace | ||
hosts: localhost | ||
vars_files: ./vars/vars.yml # variables declared in variables file are added to role automatically | ||
roles: | ||
- role: create_schematics_workspace | ||
vars: | ||
description: Automated CRAIG Testing Workspace | ||
tags: ["craig"] | ||
- name: TODO - convert to roles | ||
hosts: localhost | ||
vars_files: ./vars/vars.yml | ||
tasks: | ||
- name: Upload {{template}}.tar to Schematics Workspace | ||
command: "curl -s --request PUT \ | ||
--url 'https://schematics.cloud.ibm.com/v1/workspaces/{{ workspace.json.id }}/template_data/{{ workspace.json.template_data[0].id }}/template_repo_upload' \ | ||
-H 'Authorization: Bearer {{ token.json.access_token }}' \ | ||
-H 'Content-Type: multipart/form-data' \ | ||
--form 'file=@{{playbook_dir}}/{{template}}.tar'" | ||
async: 120 | ||
- name: Wait until {{template}}.tar has been successfully uploaded | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v1/workspaces/{{ workspace.json.id }} | ||
method: GET | ||
body_format: json | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
register: workspace_status | ||
until: workspace_status.json.status == "INACTIVE" | ||
delay: 10 | ||
retries: 50 | ||
- name: Update variablestore | ||
set_fact: | ||
variablestore: "{{ variablestore + [{'name': item, 'secure': true, 'use_default': false, 'value': ssh_key}] }}" | ||
loop: "{{template_map[template]}}" | ||
- name: Update vars in workspace | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v1/workspaces/{{ workspace.json.id }}/template_data/{{ workspace.json.template_data[0].id }}/values | ||
method: PUT | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
Content-Type: application/json | ||
body_format: json | ||
body: | ||
variablestore: "{{ variablestore }}" | ||
- name: Start generate plan action | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v1/workspaces/{{ workspace.json.id }}/plan | ||
method: POST | ||
body_format: json | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
status_code: 202 | ||
register: job | ||
- name: Ensure generate plan finishes | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v2/jobs/{{job.json.activityid}} | ||
method: GET | ||
body_format: json | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
register: plan | ||
until: plan.json.status.workspace_job_status.status_code == "job_finished" or plan.json.status.workspace_job_status.status_code == "job_failed" | ||
failed_when: plan.json.status.workspace_job_status.status_code == "job_failed" | ||
delay: 90 | ||
retries: 50 | ||
- name: Start apply plan action | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v1/workspaces/{{workspace.json.id}}/apply | ||
method: PUT | ||
body_format: json | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
status_code: 202 | ||
register: apply | ||
- name: Ensure apply plan finishes | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v2/jobs/{{apply.json.activityid}} | ||
method: GET | ||
body_format: json | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
register: apply_plan | ||
until: apply_plan.json.status.workspace_job_status.status_code == "job_finished" or apply_plan.json.status.workspace_job_status.status_code == "job_failed" | ||
failed_when: apply_plan.json.status.workspace_job_status.status_code == "job_failed" | ||
delay: 120 | ||
retries: 50 | ||
- name: Start destroy action | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v1/workspaces/{{workspace.json.id}}/destroy | ||
method: PUT | ||
body_format: json | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
status_code: 202 | ||
register: destroy | ||
- name: Ensure destory finishes | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v2/jobs/{{destroy.json.activityid}} | ||
method: GET | ||
body_format: json | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
register: destroy_plan | ||
until: destroy_plan.json.status.workspace_job_status.status_code == "job_finished" or destroy_plan.json.status.workspace_job_status.status_code == "job_failed" | ||
failed_when: destroy_plan.json.status.workspace_job_status.status_code == "job_failed" | ||
delay: 120 | ||
retries: 50 | ||
- name: Delete local {{template}}.tar file | ||
file: | ||
state: absent | ||
path: /{{playbook_dir}}/{{template}}.tar |
38 changes: 38 additions & 0 deletions
38
ansible/template-test/roles/create_schematics_workspace/README.md
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,38 @@ | ||
Role Name | ||
========= | ||
|
||
A brief description of the role goes here. | ||
|
||
Requirements | ||
------------ | ||
|
||
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. | ||
|
||
Dependencies | ||
------------ | ||
|
||
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: | ||
|
||
- hosts: servers | ||
roles: | ||
- { role: username.rolename, x: 42 } | ||
|
||
License | ||
------- | ||
|
||
BSD | ||
|
||
Author Information | ||
------------------ | ||
|
||
An optional section for the role authors to include contact information, or a website (HTML is not allowed). |
2 changes: 2 additions & 0 deletions
2
ansible/template-test/roles/create_schematics_workspace/defaults/main.yml
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,2 @@ | ||
--- | ||
# defaults file for create_schematics_workspace |
2 changes: 2 additions & 0 deletions
2
ansible/template-test/roles/create_schematics_workspace/handlers/main.yml
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,2 @@ | ||
--- | ||
# handlers file for create_schematics_workspace |
52 changes: 52 additions & 0 deletions
52
ansible/template-test/roles/create_schematics_workspace/meta/main.yml
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,52 @@ | ||
galaxy_info: | ||
author: your name | ||
description: your role description | ||
company: your company (optional) | ||
|
||
# If the issue tracker for your role is not on github, uncomment the | ||
# next line and provide a value | ||
# issue_tracker_url: http://example.com/issue/tracker | ||
|
||
# Choose a valid license ID from https://spdx.org - some suggested licenses: | ||
# - BSD-3-Clause (default) | ||
# - MIT | ||
# - GPL-2.0-or-later | ||
# - GPL-3.0-only | ||
# - Apache-2.0 | ||
# - CC-BY-4.0 | ||
license: license (GPL-2.0-or-later, MIT, etc) | ||
|
||
min_ansible_version: 2.1 | ||
|
||
# If this a Container Enabled role, provide the minimum Ansible Container version. | ||
# min_ansible_container_version: | ||
|
||
# | ||
# Provide a list of supported platforms, and for each platform a list of versions. | ||
# If you don't wish to enumerate all versions for a particular platform, use 'all'. | ||
# To view available platforms and versions (or releases), visit: | ||
# https://galaxy.ansible.com/api/v1/platforms/ | ||
# | ||
# platforms: | ||
# - name: Fedora | ||
# versions: | ||
# - all | ||
# - 25 | ||
# - name: SomePlatform | ||
# versions: | ||
# - all | ||
# - 1.0 | ||
# - 7 | ||
# - 99.99 | ||
|
||
galaxy_tags: [] | ||
# List tags for your role here, one per line. A tag is a keyword that describes | ||
# and categorizes the role. Users find roles by searching for tags. Be sure to | ||
# remove the '[]' above, if you add tags to this list. | ||
# | ||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters. | ||
# Maximum 20 tags per role. | ||
|
||
dependencies: [] | ||
# List your role dependencies here, one per line. Be sure to remove the '[]' above, | ||
# if you add dependencies to this list. |
19 changes: 19 additions & 0 deletions
19
ansible/template-test/roles/create_schematics_workspace/tasks/main.yml
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,19 @@ | ||
--- | ||
# tasks file for create_schematics_workspace | ||
- name: Create Schematics Workspace | ||
uri: | ||
url: https://schematics.cloud.ibm.com/v1/workspaces | ||
method: POST | ||
headers: | ||
Authorization: Bearer {{token.json.access_token}} | ||
body_format: json | ||
body: | ||
"name": "{{ workspace_name }}" | ||
"resource_group": "{{ resource_group }}" | ||
"type": ["terraform_v1.5"] | ||
"location": "{{ region }}" | ||
"description": "{{ description }}" | ||
"tags": "{{ tags }}" | ||
"template_data": [{ "type": "terraform_v1.5"}] | ||
status_code: 201 | ||
register: workspace |
2 changes: 2 additions & 0 deletions
2
ansible/template-test/roles/create_schematics_workspace/tests/inventory
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,2 @@ | ||
localhost | ||
|
5 changes: 5 additions & 0 deletions
5
ansible/template-test/roles/create_schematics_workspace/tests/test.yml
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,5 @@ | ||
--- | ||
- hosts: localhost | ||
remote_user: root | ||
roles: | ||
- create_schematics_workspace |
2 changes: 2 additions & 0 deletions
2
ansible/template-test/roles/create_schematics_workspace/vars/main.yml
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,2 @@ | ||
--- | ||
# vars file for create_schematics_workspace |
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,38 @@ | ||
Role Name | ||
========= | ||
|
||
A brief description of the role goes here. | ||
|
||
Requirements | ||
------------ | ||
|
||
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. | ||
|
||
Dependencies | ||
------------ | ||
|
||
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: | ||
|
||
- hosts: servers | ||
roles: | ||
- { role: username.rolename, x: 42 } | ||
|
||
License | ||
------- | ||
|
||
BSD | ||
|
||
Author Information | ||
------------------ | ||
|
||
An optional section for the role authors to include contact information, or a website (HTML is not allowed). |
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,2 @@ | ||
--- | ||
# defaults file for get_iam_token |
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,2 @@ | ||
--- | ||
# handlers file for get_iam_token |
Oops, something went wrong.