Skip to content

Commit

Permalink
fix scenario 2 (#73)
Browse files Browse the repository at this point in the history
fix scenario 2

Reviewed-by: Anton Sidelnikov
  • Loading branch information
Polina-Gubina authored Jan 11, 2024
1 parent f285a68 commit 5d9da72
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 35 deletions.
2 changes: 1 addition & 1 deletion playbooks/_scenario16_simple_heat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
template: "files/scenario16_stack_template.yaml"
name: "{{ stack_name }}"
parameters:
public_net_id: "{{ nets['openstack_networks'][0]['id'] }}"
public_net_id: "{{ nets['networks'][0]['id'] }}"

# - name: Query Stack
# openstack.cloud.stack_info:
Expand Down
2 changes: 1 addition & 1 deletion playbooks/files/get_server_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
server = conn.compute.find_server(sys.argv[1])

if server:
metadata = server.get_metadata(conn.compute)
metadata = conn.compute.get_server_metadata(server=server)
42 changes: 26 additions & 16 deletions playbooks/scenario2_simple_ecs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
test_keypair_name: "{{ (prefix + '-kp') }}"
test_network_name: "{{ ( prefix + '-net') }}"
test_image: Standard_Fedora_37_latest
test_flavor: s2.medium.2
keypair_private_key_dest: "{{ ('~/.ssh/' + (prefix + '-kp') + '.pem') }}"

- name: Query specific flavor
openstack.cloud.compute_flavor_info:
Expand All @@ -23,7 +25,7 @@
# using s2.medium.2 as fallback in case the flavor from inv is not available in the env
- set_fact:
test_flavor: s2.medium.2
when: flavor_result.openstack_flavors | length==0
when: flavor_result.flavors | length==0

- debug:
msg: "Using prefix {{ prefix }}"
Expand All @@ -41,12 +43,17 @@

- block:

- name: Create Keypair
include_role:
name: opentelekomcloud.keypair
vars:
keypair_name: "{{ test_keypair_name }}"
state: "present"
- name: Create KeyPair
openstack.cloud.keypair:
state: present
name: "{{ test_keypair_name }}"
register: keypair_output

- name: Save private key
copy:
dest: "{{ keypair_private_key_dest }}"
content: "{{ keypair_output['keypair']['private_key'] }}"
mode: 0600

- name: List Networks
openstack.cloud.networks_info:
Expand Down Expand Up @@ -112,7 +119,7 @@

- name: get server id
set_fact:
server_id: "{{ server.id }}"
server_id: "{{ server.server.id }}"

- name: Attach FIP
openstack.cloud.floating_ip:
Expand All @@ -130,7 +137,7 @@
- "az=default"

- set_fact:
server_ip: "{{ server['openstack_servers'][0]['public_v4'] }}"
server_ip: "{{ server['servers'][0]['access_ipv4'] }}"
tags:
- "metric=create_server"
- "az=default"
Expand Down Expand Up @@ -223,11 +230,14 @@
state: absent
network_name: "{{ test_network_name }}"

- name: Delete Keypair
include_role:
name: opentelekomcloud.keypair
vars:
keypair_name: "{{ test_keypair_name }}"
force_delete_key: true
state: "absent"
- name: Delete KeyPair
openstack.cloud.keypair:
state: absent
name: "{{ test_keypair_name }}"

- name: delete private key
file:
path: "{{ keypair_private_key_dest }}"
state: absent

ignore_errors: true
34 changes: 22 additions & 12 deletions playbooks/scenario2a_ecs_az.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
test_security_group_name: "{{ (prefix + '-sg') }}"
test_keypair_name: "{{ (prefix + '-kp') }}"
test_network_name: "{{ ( prefix + '-net') }}"
test_flavor: s2.medium.2
keypair_private_key_dest: "{{ ('~/.ssh/' + (prefix + '-kp') + '.pem') }}"

- name: Query specific flavor
openstack.cloud.compute_flavor_info:
Expand All @@ -27,15 +29,21 @@
# using s2.medium.2 as fallback in case the flavor from inv is not available in the env
- set_fact:
test_flavor: s2.medium.2
when: flavor_result.openstack_flavors | length==0
when: flavor_result.flavors | length==0

- block:

- name: Create Keypair
include_role:
name: keypair
vars:
keypair_name: "{{ test_keypair_name }}"
- name: Create KeyPair
openstack.cloud.keypair:
state: present
name: "{{ test_keypair_name }}"
register: keypair_output

- name: Save private key
copy:
dest: "{{ keypair_private_key_dest }}"
content: "{{ keypair_output['keypair']['private_key'] }}"
mode: 0600

- name: Create VPC
include_role:
Expand Down Expand Up @@ -89,13 +97,15 @@
state: absent
network_name: "{{ test_network_name }}"

- name: Delete KP
include_role:
name: keypair
vars:
keypair_name: "{{ test_keypair_name }}"
- name: Delete KeyPair
openstack.cloud.keypair:
state: absent
name: "{{ test_keypair_name }}"

- name: delete private key
file:
path: "{{ keypair_private_key_dest }}"
state: absent
force_delete_key: true

- name: Pause for 5 minutes to give Neutron time
pause:
Expand Down
4 changes: 2 additions & 2 deletions playbooks/scenario2c_coreos_az.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

- name: Query specific flavor
openstack.cloud.compute_flavor_info:
name: "{{ test_flavor }}"
name: "s3.medium.2"
register: flavor_result

# using s2.medium.2 as fallback in case the flavor from inv is not available in the env
- set_fact:
test_flavor: s2.medium.2
when: flavor_result.openstack_flavors | length==0
when: flavor_result.flavors | length==0

- name: Find whether we already have the image
openstack.cloud.image_info:
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
ansible==5.8.0
dnspython==2.4.2
otcextensions==0.30.9
openstacksdk==2.0.0
6 changes: 3 additions & 3 deletions roles/server_create_delete/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

- name: get server id
set_fact:
server_id: "{{ server.id }}"
server_id: "{{ server.server.id }}"

- name: Attach FIP
openstack.cloud.floating_ip:
Expand All @@ -38,7 +38,7 @@
- "az={{ availability_zone }}"

- set_fact:
server_ip: "{{ server['openstack_servers'][0]['public_v4'] }}"
server_ip: "{{ server['servers'][0]['access_ipv4'] }}"
tags:
- "metric=create_server{{ metric_suffix }}"
- "az={{ availability_zone }}"
Expand Down Expand Up @@ -85,4 +85,4 @@

- assert:
that:
- server.openstack_servers | length == 0
- server.servers | length == 0

0 comments on commit 5d9da72

Please sign in to comment.