From 963dad5f0a5aefe6be2dce7c7b66ff4d9cc9c1b3 Mon Sep 17 00:00:00 2001 From: Jakub Veverka Date: Fri, 30 Oct 2020 10:14:29 +0100 Subject: [PATCH 1/4] Reformat GCP_VM_Create.yml file --- GCP_VM_Create.yml | 66 +++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/GCP_VM_Create.yml b/GCP_VM_Create.yml index 9782ed2..60d42bb 100644 --- a/GCP_VM_Create.yml +++ b/GCP_VM_Create.yml @@ -9,36 +9,36 @@ region: "europe-west3" tasks: - - name: create a disk - gcp_compute_disk: - name: "{{ vm_disk_name | default('ansible-tower-test-disk', true) }}" - size_gb: 50 - source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' - zone: "{{ zone }}" - project: "{{ gcp_project }}" - state: present - register: disk - - name: create a address - gcp_compute_address: - name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" - region: "{{ region }}" - project: "{{ gcp_project }}" - state: present - register: address - - name: create a instance - gcp_compute_instance: - state: present - name: "{{ vm_name | default('ansible-tower-test', true) }}" - machine_type: n1-standard-1 - disks: - - auto_delete: true - boot: true - source: "{{ disk }}" - network_interfaces: - - network: null # use default - access_configs: - - name: 'External NAT' - nat_ip: "{{ address }}" - type: 'ONE_TO_ONE_NAT' - zone: "{{ zone }}" - project: "{{ gcp_project }}" + - name: create a disk + gcp_compute_disk: + name: "{{ vm_disk_name | default('ansible-tower-test-disk', true) }}" + size_gb: 50 + source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' + zone: "{{ zone }}" + project: "{{ gcp_project }}" + state: present + register: disk + - name: create a address + gcp_compute_address: + name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" + region: "{{ region }}" + project: "{{ gcp_project }}" + state: present + register: address + - name: create a instance + gcp_compute_instance: + state: present + name: "{{ vm_name | default('ansible-tower-test', true) }}" + machine_type: n1-standard-1 + disks: + - auto_delete: true + boot: true + source: "{{ disk }}" + network_interfaces: + - network: null # use default + access_configs: + - name: 'External NAT' + nat_ip: "{{ address }}" + type: 'ONE_TO_ONE_NAT' + zone: "{{ zone }}" + project: "{{ gcp_project }}" From b4c2b88556f70053d0d2840318e72cfc0febedbf Mon Sep 17 00:00:00 2001 From: Jakub Veverka Date: Fri, 30 Oct 2020 10:15:08 +0100 Subject: [PATCH 2/4] Configure Ansible Tower to use execution Container Group mainly documentaiton of how to set OpenShift and Tower. Custom container image had to be used because there gcp modules don't run on default Ansible Tower instance group. --- GCP_VM_Delete.yml | 8 +++++-- README.md | 33 +++++++++++++++++++++++++- ocp-setup/rb-tower-container-group.yml | 13 ++++++++++ ocp-setup/role-pod-manager.yml | 25 +++++++++++++++++++ ocp-setup/sa-tower-container-group.yml | 5 ++++ 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 ocp-setup/rb-tower-container-group.yml create mode 100644 ocp-setup/role-pod-manager.yml create mode 100644 ocp-setup/sa-tower-container-group.yml diff --git a/GCP_VM_Delete.yml b/GCP_VM_Delete.yml index 2fe2f1c..94f090e 100644 --- a/GCP_VM_Delete.yml +++ b/GCP_VM_Delete.yml @@ -5,8 +5,6 @@ gather_facts: no vars: gcp_project: ceenter - scopes: - - https://www.googleapis.com/auth/compute zone: "europe-west3-a" region: "europe-west3" @@ -17,3 +15,9 @@ name: "{{ vm_name | default('ansible-tower-test', true) }}" zone: "{{ zone }}" project: "{{ gcp_project }}" + - name: delete an address + gcp_compute_address: + name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" + region: "{{ region }}" + project: "{{ gcp_project }}" + state: absent diff --git a/README.md b/README.md index b1c3b3f..856ff5f 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,9 @@ Download [GCP credentials](https://docs.ansible.com/ansible/latest/scenario_guid ansible-playbook GCP_VM_Create.yml ``` -## Ansible Tower Setup +## Ansible Tower + +### Tower setup Create Credential: - GCP connection @@ -68,3 +70,32 @@ Create Job Templates: Authenticate Ansible Tower to Automation-hub: - Retrieve token at https://cloud.redhat.com/ansible/automation-hub/token - Update token in Ansible Tower: https://www.ansible.com/blog/installing-and-using-collections-on-ansible-tower + +### OpenShift setup + +Additional Container Group on OpenShift +- `oc create -n tower -f ocp-setup/role-pod-manager.yml` +- `oc create -n tower -f ocp-setup/sa-tower-container-group.yml` +- `oc create -n tower -f ocp-setup/rb-tower-container-group.yml` + +Download serviceaccount credentials, e.g. from ui download serviceaccount kubeconfig. + +Customize Pod Spec on Instance Group +```yaml +--- +apiVersion: v1 +kind: Pod +metadata: + namespace: tower +spec: + containers: + - image: quay.io/ceenter/ansible-runner-google:1.4.6 + tty: true + stdin: true + imagePullPolicy: Always + args: + - sleep + - infinity +``` + +Container image is build in [ansible-runner-images repository](https://github.com/ceenter/ansible-runner-images). diff --git a/ocp-setup/rb-tower-container-group.yml b/ocp-setup/rb-tower-container-group.yml new file mode 100644 index 0000000..2610e46 --- /dev/null +++ b/ocp-setup/rb-tower-container-group.yml @@ -0,0 +1,13 @@ +--- +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: tower-container-group +subjects: + - kind: ServiceAccount + name: tower-container-group + namespace: tower +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: pod-manager diff --git a/ocp-setup/role-pod-manager.yml b/ocp-setup/role-pod-manager.yml new file mode 100644 index 0000000..822f973 --- /dev/null +++ b/ocp-setup/role-pod-manager.yml @@ -0,0 +1,25 @@ +--- +# Role for managing Pods, presumably by Ansible Tower +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: pod-manager +rules: + - verbs: + - get + - list + - watch + - create + - update + - patch + - delete + apiGroups: + - '' + resources: + - pods + - verbs: + - create + apiGroups: + - '' + resources: + - pods/exec diff --git a/ocp-setup/sa-tower-container-group.yml b/ocp-setup/sa-tower-container-group.yml new file mode 100644 index 0000000..15e5e5d --- /dev/null +++ b/ocp-setup/sa-tower-container-group.yml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: tower-container-group \ No newline at end of file From 9a117624ceacb94c0af3cbe7c4073a19247c06ac Mon Sep 17 00:00:00 2001 From: Jakub Veverka Date: Fri, 30 Oct 2020 17:48:50 +0100 Subject: [PATCH 3/4] Create Ansible Role for managing GCP VM - parametrize option for VM type --- GCP_VM_Create.yml | 36 ++-------------------------------- GCP_VM_Delete.yml | 16 +++------------ roles/gcp_vm/defaults/main.yml | 3 +++ roles/gcp_vm/tasks/create.yml | 34 ++++++++++++++++++++++++++++++++ roles/gcp_vm/tasks/delete.yml | 13 ++++++++++++ roles/gcp_vm/tasks/main.yml | 8 ++++++++ 6 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 roles/gcp_vm/defaults/main.yml create mode 100644 roles/gcp_vm/tasks/create.yml create mode 100644 roles/gcp_vm/tasks/delete.yml create mode 100644 roles/gcp_vm/tasks/main.yml diff --git a/GCP_VM_Create.yml b/GCP_VM_Create.yml index 60d42bb..8c7188d 100644 --- a/GCP_VM_Create.yml +++ b/GCP_VM_Create.yml @@ -8,37 +8,5 @@ zone: "europe-west3-a" region: "europe-west3" - tasks: - - name: create a disk - gcp_compute_disk: - name: "{{ vm_disk_name | default('ansible-tower-test-disk', true) }}" - size_gb: 50 - source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' - zone: "{{ zone }}" - project: "{{ gcp_project }}" - state: present - register: disk - - name: create a address - gcp_compute_address: - name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" - region: "{{ region }}" - project: "{{ gcp_project }}" - state: present - register: address - - name: create a instance - gcp_compute_instance: - state: present - name: "{{ vm_name | default('ansible-tower-test', true) }}" - machine_type: n1-standard-1 - disks: - - auto_delete: true - boot: true - source: "{{ disk }}" - network_interfaces: - - network: null # use default - access_configs: - - name: 'External NAT' - nat_ip: "{{ address }}" - type: 'ONE_TO_ONE_NAT' - zone: "{{ zone }}" - project: "{{ gcp_project }}" + roles: + - name: gcp_vm diff --git a/GCP_VM_Delete.yml b/GCP_VM_Delete.yml index 94f090e..6e222c1 100644 --- a/GCP_VM_Delete.yml +++ b/GCP_VM_Delete.yml @@ -7,17 +7,7 @@ gcp_project: ceenter zone: "europe-west3-a" region: "europe-west3" + gcp_vm_state_present: false - tasks: - - name: delete an instance - gcp_compute_instance: - state: absent - name: "{{ vm_name | default('ansible-tower-test', true) }}" - zone: "{{ zone }}" - project: "{{ gcp_project }}" - - name: delete an address - gcp_compute_address: - name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" - region: "{{ region }}" - project: "{{ gcp_project }}" - state: absent + roles: + - name: gcp_vm diff --git a/roles/gcp_vm/defaults/main.yml b/roles/gcp_vm/defaults/main.yml new file mode 100644 index 0000000..345fc7f --- /dev/null +++ b/roles/gcp_vm/defaults/main.yml @@ -0,0 +1,3 @@ +--- +gcp_vm_state_present: true +gcp_vm_machine_type: n1-standard-1 \ No newline at end of file diff --git a/roles/gcp_vm/tasks/create.yml b/roles/gcp_vm/tasks/create.yml new file mode 100644 index 0000000..8607969 --- /dev/null +++ b/roles/gcp_vm/tasks/create.yml @@ -0,0 +1,34 @@ +--- +- name: create a disk + gcp_compute_disk: + name: "{{ vm_disk_name | default('ansible-tower-test-disk', true) }}" + size_gb: 50 + source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' + zone: "{{ zone }}" + project: "{{ gcp_project }}" + state: present + register: disk +- name: create a address + gcp_compute_address: + name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" + region: "{{ region }}" + project: "{{ gcp_project }}" + state: present + register: address +- name: create a instance + gcp_compute_instance: + state: present + name: "{{ vm_name | default('ansible-tower-test', true) }}" + machine_type: "{{ gcp_vm_machine_type }}" + disks: + - auto_delete: true + boot: true + source: "{{ disk }}" + network_interfaces: + - network: null # use default + access_configs: + - name: 'External NAT' + nat_ip: "{{ address }}" + type: 'ONE_TO_ONE_NAT' + zone: "{{ zone }}" + project: "{{ gcp_project }}" \ No newline at end of file diff --git a/roles/gcp_vm/tasks/delete.yml b/roles/gcp_vm/tasks/delete.yml new file mode 100644 index 0000000..f300a27 --- /dev/null +++ b/roles/gcp_vm/tasks/delete.yml @@ -0,0 +1,13 @@ +--- +- name: delete an instance + gcp_compute_instance: + state: absent + name: "{{ vm_name | default('ansible-tower-test', true) }}" + zone: "{{ zone }}" + project: "{{ gcp_project }}" +- name: delete an address + gcp_compute_address: + name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" + region: "{{ region }}" + project: "{{ gcp_project }}" + state: absent \ No newline at end of file diff --git a/roles/gcp_vm/tasks/main.yml b/roles/gcp_vm/tasks/main.yml new file mode 100644 index 0000000..9de3228 --- /dev/null +++ b/roles/gcp_vm/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- name: Include Create GCP VM Tasks + include_tasks: create.yml + when: gcp_vm_state_present + +- name: Include Delete GCP VM Tasks + include_tasks: delete.yml + when: not gcp_vm_state_present From ef81ffdf991ce56759a449afff4153e32d4a8fee Mon Sep 17 00:00:00 2001 From: Jakub Veverka Date: Fri, 30 Oct 2020 18:11:16 +0100 Subject: [PATCH 4/4] Remove ansible playbooks and roles all Ansible and setup is migrated to https://github.com/ceenter/ceenter --- .gitignore | 3 - GCP_VM_Create.yml | 12 ---- GCP_VM_Delete.yml | 13 ---- README.md | 98 -------------------------- RHV_VM_Create.yml | 21 ------ ansible.cfg | 15 ---- collections/requirements.yml | 5 -- ocp-setup/rb-tower-container-group.yml | 13 ---- ocp-setup/role-pod-manager.yml | 25 ------- ocp-setup/sa-tower-container-group.yml | 5 -- roles/gcp_vm/defaults/main.yml | 3 - roles/gcp_vm/tasks/create.yml | 34 --------- roles/gcp_vm/tasks/delete.yml | 13 ---- roles/gcp_vm/tasks/main.yml | 8 --- test.yml | 14 ---- 15 files changed, 282 deletions(-) delete mode 100644 .gitignore delete mode 100644 GCP_VM_Create.yml delete mode 100644 GCP_VM_Delete.yml delete mode 100644 RHV_VM_Create.yml delete mode 100644 ansible.cfg delete mode 100644 collections/requirements.yml delete mode 100644 ocp-setup/rb-tower-container-group.yml delete mode 100644 ocp-setup/role-pod-manager.yml delete mode 100644 ocp-setup/sa-tower-container-group.yml delete mode 100644 roles/gcp_vm/defaults/main.yml delete mode 100644 roles/gcp_vm/tasks/create.yml delete mode 100644 roles/gcp_vm/tasks/delete.yml delete mode 100644 roles/gcp_vm/tasks/main.yml delete mode 100644 test.yml diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 8d13d57..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -collections/* -!collections/requirements.yml -secrets/* \ No newline at end of file diff --git a/GCP_VM_Create.yml b/GCP_VM_Create.yml deleted file mode 100644 index 8c7188d..0000000 --- a/GCP_VM_Create.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Create an VM instance - hosts: localhost - connection: local - gather_facts: no - vars: - gcp_project: ceenter - zone: "europe-west3-a" - region: "europe-west3" - - roles: - - name: gcp_vm diff --git a/GCP_VM_Delete.yml b/GCP_VM_Delete.yml deleted file mode 100644 index 6e222c1..0000000 --- a/GCP_VM_Delete.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: Delete an VM instance - hosts: localhost - connection: local - gather_facts: no - vars: - gcp_project: ceenter - zone: "europe-west3-a" - region: "europe-west3" - gcp_vm_state_present: false - - roles: - - name: gcp_vm diff --git a/README.md b/README.md index 856ff5f..bd3b7c6 100644 --- a/README.md +++ b/README.md @@ -1,101 +1,3 @@ # Technical Technical repo for Ceenter infrastructure - -## Local setup - -Steps to prepare local environment. - -### Prerequisites - -ansible 2.9+ - -### Install Ansible collections - -Configure ansible.cfg: -Download ansible-hub token from https://cloud.redhat.com/ansible/automation-hub/token - -update ansible.cfg to include: -``` ini -[defaults] -collections_paths = ./collections - -[galaxy] -server_list = automation_hub - -[galaxy_server.automation_hub] -url=https://cloud.redhat.com/api/automation-hub/ -auth_url=https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token -token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -``` - -Install dependent collections -```shell -ansible-galaxy collection install -r ./collections/requirements.yml -``` - -Detailed [blog about setting up env](https://www.ansible.com/blog/hands-on-with-ansible-collections) for automation-hub collections. - -Install google.cloud requirements: - -``` shell -yum install python-requests -pip install requests google-auth -``` - -Download [GCP credentials](https://docs.ansible.com/ansible/latest/scenario_guides/guide_gce.html#credentials). - -### Create VM on GCP - -``` shell -ansible-playbook GCP_VM_Create.yml -``` - -## Ansible Tower - -### Tower setup - -Create Credential: -- GCP connection -- Github -- RHV - -Create Project: -- technical - -Create Job Templates: -- GCP Create VM -- RHV Create VM - -Authenticate Ansible Tower to Automation-hub: -- Retrieve token at https://cloud.redhat.com/ansible/automation-hub/token -- Update token in Ansible Tower: https://www.ansible.com/blog/installing-and-using-collections-on-ansible-tower - -### OpenShift setup - -Additional Container Group on OpenShift -- `oc create -n tower -f ocp-setup/role-pod-manager.yml` -- `oc create -n tower -f ocp-setup/sa-tower-container-group.yml` -- `oc create -n tower -f ocp-setup/rb-tower-container-group.yml` - -Download serviceaccount credentials, e.g. from ui download serviceaccount kubeconfig. - -Customize Pod Spec on Instance Group -```yaml ---- -apiVersion: v1 -kind: Pod -metadata: - namespace: tower -spec: - containers: - - image: quay.io/ceenter/ansible-runner-google:1.4.6 - tty: true - stdin: true - imagePullPolicy: Always - args: - - sleep - - infinity -``` - -Container image is build in [ansible-runner-images repository](https://github.com/ceenter/ansible-runner-images). diff --git a/RHV_VM_Create.yml b/RHV_VM_Create.yml deleted file mode 100644 index 7388157..0000000 --- a/RHV_VM_Create.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Provision VM from template - hosts: localhost - connection: local - gather_facts: no - - vars: -# datacenter: Default - - tasks: - - - name: Create and run RHEL VM from template - ovirt_vm: - name: "{{ vm_name | default('test0002', true) }}" - template: default_template - cluster: "{{ cluster | default('Default', true) }}" - memory: "{{vm_memory | default('1GiB', true) }}" - high_availability: true - description: "{{ description | default(omit) }}" - state: running - wait: yes diff --git a/ansible.cfg b/ansible.cfg deleted file mode 100644 index 9feb9fe..0000000 --- a/ansible.cfg +++ /dev/null @@ -1,15 +0,0 @@ -# config file for ansible -- https://ansible.com/ -# =============================================== - -# nearly all parameters can be overridden in ansible-playbook -# or with command line flags. ansible will read ANSIBLE_CONFIG, -# ansible.cfg in the current working directory, .ansible.cfg in -# the home directory or /etc/ansible/ansible.cfg, whichever it -# finds first - -[defaults] -collections_paths = ./collections -stdout_callback = yaml -callback_whitelist = yaml -bin_ansible_callbacks = True -nocows = 1 diff --git a/collections/requirements.yml b/collections/requirements.yml deleted file mode 100644 index 86c7f8c..0000000 --- a/collections/requirements.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -collections: - - name: google.cloud - source: https://cloud.redhat.com/api/automation-hub/ - version: 1.0.0 \ No newline at end of file diff --git a/ocp-setup/rb-tower-container-group.yml b/ocp-setup/rb-tower-container-group.yml deleted file mode 100644 index 2610e46..0000000 --- a/ocp-setup/rb-tower-container-group.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -kind: RoleBinding -apiVersion: rbac.authorization.k8s.io/v1 -metadata: - name: tower-container-group -subjects: - - kind: ServiceAccount - name: tower-container-group - namespace: tower -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: Role - name: pod-manager diff --git a/ocp-setup/role-pod-manager.yml b/ocp-setup/role-pod-manager.yml deleted file mode 100644 index 822f973..0000000 --- a/ocp-setup/role-pod-manager.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -# Role for managing Pods, presumably by Ansible Tower -apiVersion: rbac.authorization.k8s.io/v1 -kind: Role -metadata: - name: pod-manager -rules: - - verbs: - - get - - list - - watch - - create - - update - - patch - - delete - apiGroups: - - '' - resources: - - pods - - verbs: - - create - apiGroups: - - '' - resources: - - pods/exec diff --git a/ocp-setup/sa-tower-container-group.yml b/ocp-setup/sa-tower-container-group.yml deleted file mode 100644 index 15e5e5d..0000000 --- a/ocp-setup/sa-tower-container-group.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: tower-container-group \ No newline at end of file diff --git a/roles/gcp_vm/defaults/main.yml b/roles/gcp_vm/defaults/main.yml deleted file mode 100644 index 345fc7f..0000000 --- a/roles/gcp_vm/defaults/main.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -gcp_vm_state_present: true -gcp_vm_machine_type: n1-standard-1 \ No newline at end of file diff --git a/roles/gcp_vm/tasks/create.yml b/roles/gcp_vm/tasks/create.yml deleted file mode 100644 index 8607969..0000000 --- a/roles/gcp_vm/tasks/create.yml +++ /dev/null @@ -1,34 +0,0 @@ ---- -- name: create a disk - gcp_compute_disk: - name: "{{ vm_disk_name | default('ansible-tower-test-disk', true) }}" - size_gb: 50 - source_image: 'projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts' - zone: "{{ zone }}" - project: "{{ gcp_project }}" - state: present - register: disk -- name: create a address - gcp_compute_address: - name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" - region: "{{ region }}" - project: "{{ gcp_project }}" - state: present - register: address -- name: create a instance - gcp_compute_instance: - state: present - name: "{{ vm_name | default('ansible-tower-test', true) }}" - machine_type: "{{ gcp_vm_machine_type }}" - disks: - - auto_delete: true - boot: true - source: "{{ disk }}" - network_interfaces: - - network: null # use default - access_configs: - - name: 'External NAT' - nat_ip: "{{ address }}" - type: 'ONE_TO_ONE_NAT' - zone: "{{ zone }}" - project: "{{ gcp_project }}" \ No newline at end of file diff --git a/roles/gcp_vm/tasks/delete.yml b/roles/gcp_vm/tasks/delete.yml deleted file mode 100644 index f300a27..0000000 --- a/roles/gcp_vm/tasks/delete.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- name: delete an instance - gcp_compute_instance: - state: absent - name: "{{ vm_name | default('ansible-tower-test', true) }}" - zone: "{{ zone }}" - project: "{{ gcp_project }}" -- name: delete an address - gcp_compute_address: - name: "{{ vm_address_name | default('ansible-tower-test-address', true) }}" - region: "{{ region }}" - project: "{{ gcp_project }}" - state: absent \ No newline at end of file diff --git a/roles/gcp_vm/tasks/main.yml b/roles/gcp_vm/tasks/main.yml deleted file mode 100644 index 9de3228..0000000 --- a/roles/gcp_vm/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- name: Include Create GCP VM Tasks - include_tasks: create.yml - when: gcp_vm_state_present - -- name: Include Delete GCP VM Tasks - include_tasks: delete.yml - when: not gcp_vm_state_present diff --git a/test.yml b/test.yml deleted file mode 100644 index 2e134d1..0000000 --- a/test.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: Test Playbook - hosts: all - gather_facts: no - connection: local - - tasks: - - name: Tell me all about yourself - setup: - register: fact_variable - - - name: Show it on screen - debug: - msg: "{{ fact_variable }}"