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