-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathUnprovisioning_server.yml
97 lines (84 loc) · 2.84 KB
/
Unprovisioning_server.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Playbook for server unprovisioning:
# - Power off the server
# - Delete the HPE OneView Server Profile
# - Remove the DNS record
# - Remove the host SSH key from .ssh/known_hosts on the Ansible control node
#
# Commands that can be used to run this playbook:
# $ ansible-playbook -i "RHEL-1," Server_unprovisioning.yml --ask-vault-password
# $ ansible-playbook -i "RHEL-1,ESX7-2" Server_unprovisioning.yml --ask-vault-password
# $ ansible-playbook -i hosts Server_unprovisioning.yml --ask-vault-password
---
- name: Deleting provisioned compute module(s)
hosts: all
collections:
- hpe.oneview
gather_facts: no
vars:
# HPE Synergy Composer configuration
config: "{{ playbook_dir }}/oneview_config.json"
# - ansible_python_interpreter: python3
ansible_host_key_checking: false
validate_certs: false
ansible_forks: 5
tasks:
- name: Checking if server profile "{{ inventory_hostname }}" exists
oneview_server_profile_facts:
config: "{{ config }}"
name: "{{ inventory_hostname }}"
delegate_to: localhost
# - debug: var=server_profiles
- name : Getting server profile "{{ inventory_hostname }}" information
oneview_server_profile:
config: "{{ config }}"
state: "present"
data:
name: "{{ inventory_hostname }}"
delegate_to: localhost
when: server_profiles
# - debug: var=server_hardware
- name: Powering off server hardware "{{ inventory_hostname }}"
oneview_server_hardware:
config: "{{ config }}"
state: power_state_set
data:
name : "{{ server_hardware.name }}"
powerStateData:
powerState: "Off"
powerControl: "PressAndHold"
delegate_to: localhost
when: server_profiles
- name: Deleting server profile "{{ inventory_hostname }}"
oneview_server_profile:
config: "{{ config }}"
state: "absent"
data:
name: "{{ inventory_hostname }}"
delegate_to: localhost
when: server_profiles
register: result
- name: Result of the task to delete the server profile
debug:
msg: "{{ result.msg }}"
when: server_profiles
- name: Removing {{ inventory_hostname }} SSH key
known_hosts:
name: '{{ inventory_hostname }}'
path: ~/.ssh/known_hosts
state: absent
delegate_to: localhost
- name: Removing the DNS record from DNS server
hosts: all
gather_facts: no
vars:
ansible_forks: 5
vars_files:
vars/Windows_DNS_vars_encrypted.yml
tasks:
- name: Removing "{{ inventory_hostname }}" from "{{ dns_server }}"
community.windows.win_dns_record:
name: "{{ inventory_hostname }}"
type: "A"
zone: "{{ domain }}"
state: absent
delegate_to: "{{ dns_server }}"