Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit 699c28b

Browse files
authored
Fix virtualenv errors in lifecycle (redhat-cop#925)
Use include_tasks to avoid syntax errors or modules not found.
1 parent 9c7c869 commit 699c28b

File tree

3 files changed

+121
-120
lines changed

3 files changed

+121
-120
lines changed

ansible/lifecycle.yml

+3-120
Original file line numberDiff line numberDiff line change
@@ -26,125 +26,8 @@
2626
fail:
2727
msg: variable 'guid' must be defined and not empty
2828
29-
- when:
30-
- cloud_provider == 'ec2'
31-
- guid is defined
32-
- guid != ''
33-
- guid != '*'
34-
environment:
35-
AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}"
36-
AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}"
37-
AWS_DEFAULT_REGION: "{{aws_region_final|d(aws_region)}}"
38-
block:
39-
- when: ACTION == 'stop'
40-
name: Stop instances by (guid,env_type) tags
41-
ec2_instance:
42-
state: stopped
43-
wait: no
44-
filters:
45-
"tag:guid": "{{ guid }}"
46-
# TODO: uncomment this after a few weeks
47-
#"tag:env_type": "{{ env_type }}"
29+
- when: cloud_provider == 'ec2'
30+
include_tasks: lifecycle_ec2.yml
4831

49-
- when: ACTION == 'start'
50-
name: Start instances by (guid, env_type) tags
51-
ec2_instance:
52-
state: started
53-
wait: no
54-
filters:
55-
"tag:guid": "{{ guid }}"
56-
# TODO: uncomment this after a few weeks
57-
#"tag:env_type": "{{ env_type }}"
58-
59-
- when: ACTION == 'status'
60-
block:
61-
- name: Get EC2 facts using (guid, env_type) tag
62-
ec2_instance_facts:
63-
filters:
64-
"tag:guid": "{{ guid }}"
65-
# TODO: uncomment this after a few weeks
66-
#"tag:env_type": "{{ env_type }}"
67-
register: r_instances
68-
69-
- name: Print status information to a file
70-
copy:
71-
dest: "{{ output_dir }}/status.txt"
72-
content: |-
73-
{{ "%-60s" | format('Instance') }} State Type
74-
----------------------------------------------------------------
75-
{% for instance in r_instances.instances %}
76-
{{ "%-60s" | format(instance.tags.Name) }} {{ "%-10s" | format(instance.state.name) }} {{ instance.instance_type }}
77-
{% endfor %}
7832
- when: cloud_provider == 'osp'
79-
environment:
80-
OS_AUTH_URL: "{{ osp_auth_url }}"
81-
OS_USERNAME: "{{ osp_auth_username }}"
82-
OS_PASSWORD: "{{ osp_auth_password }}"
83-
OS_PROJECT_NAME: "{{ osp_project_name }}"
84-
OS_PROJECT_DOMAIN_ID: "{{ osp_auth_project_domain }}"
85-
OS_USER_DOMAIN_NAME: "{{ osp_auth_user_domain }}"
86-
block:
87-
- when: ACTION == 'stop'
88-
block:
89-
- name: Gather instance facts
90-
os_server_facts:
91-
filters:
92-
metadata:
93-
guid: "{{ guid }}"
94-
env_type: "{{ env_type }}"
95-
vm_state: active
96-
register: r_osp_facts
97-
98-
- when: r_osp_facts.ansible_facts.openstack_servers | length > 0
99-
block:
100-
- set_fact:
101-
all_instances: >-
102-
{{ r_osp_facts.ansible_facts.openstack_servers
103-
| json_query('[*].id') }}
104-
105-
- name: Stop all servers
106-
command: openstack server stop {{ all_instances | join(' ') }}
107-
108-
- when: ACTION == 'start'
109-
block:
110-
- name: Gather instance facts
111-
os_server_facts:
112-
filters:
113-
metadata:
114-
guid: "{{ guid }}"
115-
env_type: "{{ env_type }}"
116-
vm_state: stopped
117-
register: r_osp_facts
118-
119-
- when: r_osp_facts.ansible_facts.openstack_servers | length > 0
120-
block:
121-
- set_fact:
122-
all_instances: >-
123-
{{ r_osp_facts.ansible_facts.openstack_servers
124-
| json_query('[*].id') }}
125-
126-
- name: Start all servers
127-
command: openstack server start {{ all_instances | join(' ') }}
128-
129-
- when: ACTION == 'status'
130-
block:
131-
- name: Get OSP facts using (guid, env_type) metadata
132-
os_server_facts:
133-
filters:
134-
metadata:
135-
guid: "{{ guid }}"
136-
env_type: "{{ env_type }}"
137-
register: r_instances
138-
139-
- debug:
140-
var: r_instances
141-
142-
- name: Print status information to a file
143-
copy:
144-
dest: "{{ output_dir }}/status.txt"
145-
content: |-
146-
{{ "%-30s" | format('Instance') }} State
147-
-------------------------------------------
148-
{% for instance in r_instances.ansible_facts.openstack_servers %}
149-
{{ "%-30s" | format(instance.name) }} {{ "%-10s" | format(instance.vm_state) }}
150-
{% endfor %}
33+
include_tasks: lifecycle_osp.yml

ansible/lifecycle_ec2.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
- environment:
3+
AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}"
4+
AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}"
5+
AWS_DEFAULT_REGION: "{{aws_region_final|d(aws_region)}}"
6+
block:
7+
- when: ACTION == 'stop'
8+
name: Stop instances by (guid,env_type) tags
9+
ec2_instance:
10+
state: stopped
11+
wait: no
12+
filters:
13+
"tag:guid": "{{ guid }}"
14+
# TODO: uncomment this after a few weeks
15+
#"tag:env_type": "{{ env_type }}"
16+
17+
- when: ACTION == 'start'
18+
name: Start instances by (guid, env_type) tags
19+
ec2_instance:
20+
state: started
21+
wait: no
22+
filters:
23+
"tag:guid": "{{ guid }}"
24+
# TODO: uncomment this after a few weeks
25+
#"tag:env_type": "{{ env_type }}"
26+
27+
- when: ACTION == 'status'
28+
block:
29+
- name: Get EC2 facts using (guid, env_type) tag
30+
ec2_instance_facts:
31+
filters:
32+
"tag:guid": "{{ guid }}"
33+
# TODO: uncomment this after a few weeks
34+
#"tag:env_type": "{{ env_type }}"
35+
register: r_instances
36+
37+
- name: Print status information to a file
38+
copy:
39+
dest: "{{ output_dir }}/status.txt"
40+
content: |-
41+
{{ "%-60s" | format('Instance') }} State Type
42+
----------------------------------------------------------------
43+
{% for instance in r_instances.instances %}
44+
{{ "%-60s" | format(instance.tags.Name) }} {{ "%-10s" | format(instance.state.name) }} {{ instance.instance_type }}
45+
{% endfor %}

ansible/lifecycle_osp.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
- environment:
3+
OS_AUTH_URL: "{{ osp_auth_url }}"
4+
OS_USERNAME: "{{ osp_auth_username }}"
5+
OS_PASSWORD: "{{ osp_auth_password }}"
6+
OS_PROJECT_NAME: "{{ osp_project_name }}"
7+
OS_PROJECT_DOMAIN_ID: "{{ osp_auth_project_domain }}"
8+
OS_USER_DOMAIN_NAME: "{{ osp_auth_user_domain }}"
9+
block:
10+
- when: ACTION == 'stop'
11+
block:
12+
- name: Gather instance facts
13+
os_server_facts:
14+
filters:
15+
metadata:
16+
guid: "{{ guid }}"
17+
env_type: "{{ env_type }}"
18+
vm_state: active
19+
register: r_osp_facts
20+
21+
- when: r_osp_facts.ansible_facts.openstack_servers | length > 0
22+
block:
23+
- set_fact:
24+
all_instances: >-
25+
{{ r_osp_facts.ansible_facts.openstack_servers
26+
| json_query('[*].id') }}
27+
28+
- name: Stop all servers
29+
command: openstack server stop {{ all_instances | join(' ') }}
30+
31+
- when: ACTION == 'start'
32+
block:
33+
- name: Gather instance facts
34+
os_server_facts:
35+
filters:
36+
metadata:
37+
guid: "{{ guid }}"
38+
env_type: "{{ env_type }}"
39+
vm_state: stopped
40+
register: r_osp_facts
41+
42+
- when: r_osp_facts.ansible_facts.openstack_servers | length > 0
43+
block:
44+
- set_fact:
45+
all_instances: >-
46+
{{ r_osp_facts.ansible_facts.openstack_servers
47+
| json_query('[*].id') }}
48+
49+
- name: Start all servers
50+
command: openstack server start {{ all_instances | join(' ') }}
51+
52+
- when: ACTION == 'status'
53+
block:
54+
- name: Get OSP facts using (guid, env_type) metadata
55+
os_server_facts:
56+
filters:
57+
metadata:
58+
guid: "{{ guid }}"
59+
env_type: "{{ env_type }}"
60+
register: r_instances
61+
62+
- debug:
63+
var: r_instances
64+
65+
- name: Print status information to a file
66+
copy:
67+
dest: "{{ output_dir }}/status.txt"
68+
content: |-
69+
{{ "%-30s" | format('Instance') }} State
70+
-------------------------------------------
71+
{% for instance in r_instances.ansible_facts.openstack_servers %}
72+
{{ "%-30s" | format(instance.name) }} {{ "%-10s" | format(instance.vm_state) }}
73+
{% endfor %}

0 commit comments

Comments
 (0)