-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredfish.yml
114 lines (106 loc) · 6.21 KB
/
redfish.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
- name: Redfish & Generate Configuration Files
hosts: bmcs
gather_facts: false
tasks:
- name: Redfish Gather MACs
redfish_facts:
category: Systems
command: all
baseuri: "{{ bmcip }}"
username: "{{ bmcuser }}"
password: "{{ bmcpassword }}"
delegate_to: localhost
register: result
- name: Copy Results to Output File
copy:
content: "{{ result | to_nice_json }}"
dest: "{{inventory_hostname}}.hwprofile.json.tmp"
delegate_to: localhost
- name: Add Additional Lines to Dynamic Host Inventory File
shell: |
echo domain={{ domain }}>>hosts
echo cluster={{ cluster }}>>hosts
echo ipmi_username={{ bmcuser }}>>hosts
echo ipmi_password={{ bmcpassword }}>>hosts
delegate_to: localhost
run_once: True
- name: DNS DHCP Scope Requirements
shell: |
if (getent hosts api.{{ cluster }}.{{ domain }}>/dev/null 2>&1); then apistat="Success"; apiip=`getent hosts api.{{ cluster }}.{{ domain }}|awk {'print $1'}`; else apistat="Failed"; apiip="Error"; fi
if (getent hosts test.apps.{{ cluster }}.{{ domain }}>/dev/null 2>&1); then appstat="Success"; appip=`getent hosts test.apps.{{ cluster }}.{{ domain }}|awk {'print $1'}`; else appstat="Failed"; appip="Error"; fi
if (getent hosts ns1.{{ cluster }}.{{ domain }}>/dev/null 2>&1); then nsstat="Success"; ns1ip=`getent hosts ns1.{{ cluster }}.{{ domain }}|awk {'print $1'}`; else nsstat="Failed"; ns1ip="Error"; fi
cat << EOF >> dhcps
Hostname MacAddress IpAddress Interface Status
-------------------- -------------------- -------------------- -------------------- --------------------
api.{{ cluster }}.{{ domain }} NA $apiip VIP $apistat
*.apps.{{ cluster }}.{{ domain }} NA $appip VIP $appstat
ns1.{{ cluster }}.{{ domain }} NA $ns1ip VIP $nsstat
EOF
echo apivip=$apiip>>hosts
echo ingressvip=$appip>>hosts
echo ns1vip=$ns1ip>>hosts
echo '[masters]' >> hosts
delegate_to: localhost
run_once: True
- name: Add Master Hosts Lines To Inventory and Perform DHCP/DNS Validations
shell: |
intip="Unassigned"
if (echo {{ inventory_hostname }}|grep -q worker); then
wcount=`cat /tmp/wcount.tmp`
intip="Unassigned"
macaddress=`jq -r '.ansible_facts.redfish_facts.nic.entries[0][1][]|select(.Description=="Integrated NIC 1 Port 1 Partition 1")|.PermanentMACAddress' {{ inventory_hostname }}.hwprofile.json.tmp`
if (ip a| tr [:lower:] [:upper:]|grep -q $macaddress); then
nodename=worker-$(({{ workercount }}-1))
intip=`ip -f inet a show provisioning|sed -En -e 's/.*inet ([0-9.]+).*/\1/p'`
mv {{ inventory_hostname }}.hwprofile.json.tmp $nodename.hwprofile.json
else
nodename=worker-$wcount
wcount=$(($wcount+1))
echo "$wcount">/tmp/wcount.tmp
mv {{ inventory_hostname }}.hwprofile.json.tmp $nodename.hwprofile.json
fi
else
nodename={{ inventory_hostname }}
mv {{ inventory_hostname }}.hwprofile.json.tmp $nodename.hwprofile.json
fi
macaddress=`jq -r '.ansible_facts.redfish_facts.nic.entries[0][1][]|select(.Description=="Integrated NIC 1 Port 1 Partition 1")|.PermanentMACAddress' $nodename.hwprofile.json`
extmacaddress=`jq -r '.ansible_facts.redfish_facts.nic.entries[0][1][]|select(.Description=="Integrated NIC 1 Port 2 Partition 1")|.PermanentMACAddress' $nodename.hwprofile.json`
nicnum=`grep NIC $nodename.hwprofile.json | grep Description| grep -Fn "Integrated NIC 1 Port 1 Partition 1"|awk -F: {'print $1'} | awk '{print $0-1}'`
dhcpip=`./check_dhcp.py -m $extmacaddress|grep Offered|cut -f2 -d:|sed "s/ //g"`
extip=`getent hosts $nodename.{{ cluster }}.{{ domain }}|awk {'print $1'}`
extnet=`/usr/bin/ipcalc -n "$(/usr/sbin/ip -o addr show|grep baremetal|grep -v inet6|awk {'print $4'})"|cut -f2 -d=`
extcidr=`/usr/bin/ipcalc -p "$(/usr/sbin/ip -o addr show|grep baremetal|grep -v inet6|awk {'print $4'})"|cut -f2 -d=`
dhcpipnet=`/usr/bin/ipcalc -n $dhcpip/$extcidr |cut -f2 -d=`
extipnet=`/usr/bin/ipcalc -n $extip/$extcidr |cut -f2 -d=`
if [ $dhcpip == $extip ] && [ $dhcpipnet == $extipnet ] && [ $extnet == $extipnet ]; then dnstat="Success"; else dnstat="Failed"; fi
if (echo "$nodename"|grep -q master); then
echo "$nodename name=$nodename role=master ipmi_username={{ bmcuser }} ipmi_password={{ bmcpassword }} ipmi_address={{ bmcip }} mac=$macaddress disk=59 nicnum=$nicnum">>hosts
else
if [ $nodename == "worker-$(({{ workercount }}-1))" ]; then
echo "$nodename name=$nodename role=provisioner ipmi_username={{ bmcuser }} ipmi_password={{ bmcpassword }} ipmi_address={{ bmcip }} mac=$macaddress disk=59 nicnum=$nicnum">>hosts.provision
else
echo "$nodename name=$nodename role=worker ipmi_username={{ bmcuser }} ipmi_password={{ bmcpassword }} ipmi_address={{ bmcip }} mac=$macaddress disk=59 nicnum=$nicnum">>hosts.worker
fi
fi
cat << EOF >> dhcps
$nodename.{{ cluster }}.{{ domain }} $extmacaddress $extip External $dnstat
$nodename.{{ cluster }}.{{ domain }} $macaddress $intip Internal Success
EOF
delegate_to: localhost
- name: Refresh inventory to ensure new instances exist in inventory
meta: refresh_inventory
- name: Power Cycle Off Masters
hosts: masters
gather_facts: false
tasks:
- name: Power Cycle Off Masters
redfish_command:
category: Systems
command: PowerForceOff
baseuri: "{{ ipmi_address }}"
username: "{{ ipmi_username }}"
password: "{{ ipmi_password }}"
delegate_to: localhost
ignore_errors: true
when: lookup('env','power') == '1'