Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 1 | {# Collection of common macroses shared across MaaS #} |
| 2 | |
Hanna Arhipova | b41cf97 | 2021-04-09 01:02:37 +0300 | [diff] [blame] | 3 | |
| 4 | {%- macro REBOOT_HW_NODES(ipmi_user, ipmi_password, ipmi_devices=['']) %} |
| 5 | |
| 6 | - description: Reboot hardware computes and set to PXE boot. It needs for clean deployment |
| 7 | cmd: | |
| 8 | {%- for device in ipmi_devices %} |
Hanna Arhipova | 353dbdf | 2021-04-15 14:30:02 +0300 | [diff] [blame] | 9 | ipmitool -H {{ device }} -U {{ ipmi_user }} -P {{ ipmi_password }} -I lanplus chassis power off |
Hanna Arhipova | b41cf97 | 2021-04-09 01:02:37 +0300 | [diff] [blame] | 10 | {%- endfor %} |
| 11 | {%- for device in ipmi_devices %} |
Hanna Arhipova | 353dbdf | 2021-04-15 14:30:02 +0300 | [diff] [blame] | 12 | ipmitool -H {{ device }} -U {{ ipmi_user }} -P {{ ipmi_password }} -I lanplus chassis bootdev pxe |
Hanna Arhipova | b41cf97 | 2021-04-09 01:02:37 +0300 | [diff] [blame] | 13 | {%- endfor %} |
| 14 | node_name: {{ HOSTNAME_CFG01 }} |
| 15 | retry: {count: 1, delay: 5} |
| 16 | skip_fail: false |
| 17 | |
| 18 | {%- endmacro %} |
| 19 | |
| 20 | |
Dmitry Tyzhnenko | 80ce020 | 2019-02-07 13:27:19 +0200 | [diff] [blame] | 21 | {%- macro AUTH_IN_MAAS() %} |
| 22 | |
| 23 | - description: MaaS auth |
| 24 | cmd: bash -x /var/lib/maas/.maas_login.sh |
| 25 | node_name: {{ HOSTNAME_CFG01 }} |
| 26 | retry: {count: 1, delay: 5} |
| 27 | skip_fail: false |
| 28 | |
| 29 | {%- endmacro %} |
| 30 | |
| 31 | {%- macro SET_LOCAL_DNS() %} |
| 32 | |
| 33 | - description: Set upstream dns in MaaS |
| 34 | cmd: sleep 30; maas mirantis maas set-config name=upstream_dns value='{{ ETH0_IP_ADDRESS_CFG01 }} 8.8.8.8 8.8.4.4' |
| 35 | node_name: {{ HOSTNAME_CFG01 }} |
| 36 | retry: {count: 1, delay: 5} |
| 37 | skip_fail: false |
| 38 | |
| 39 | {%- endmacro %} |
| 40 | |
| 41 | {%- macro ADD_TEST_SSH_KEY_TO_NODES(key) %} |
| 42 | |
| 43 | - description: Add key to root user on salt minions |
| 44 | cmd: salt "*" ssh.set_auth_key root "{{ key }}" |
| 45 | node_name: {{ HOSTNAME_CFG01 }} |
| 46 | retry: {count: 1, delay: 5} |
| 47 | skip_fail: false |
| 48 | |
| 49 | - description: Add key to ubuntu user on salt minions |
| 50 | cmd: salt "*" ssh.set_auth_key ubuntu "{{ key }}" |
| 51 | node_name: {{ HOSTNAME_CFG01 }} |
| 52 | retry: {count: 1, delay: 5} |
| 53 | skip_fail: false |
| 54 | {%- endmacro %} |
| 55 | |
| 56 | {%- macro ADD_ROOT_SSH_KEY_TO_NODES() %} |
| 57 | |
| 58 | - description: Add root key to root user on salt minions |
| 59 | cmd: salt "*" ssh.set_auth_key root "$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)" |
| 60 | node_name: {{ HOSTNAME_CFG01 }} |
| 61 | retry: {count: 1, delay: 5} |
| 62 | skip_fail: false |
| 63 | |
| 64 | - description: Add root key to ubuntu user on salt minions |
| 65 | cmd: salt "*" ssh.set_auth_key ubuntu "$(ssh-keygen -y -f ~/.ssh/id_rsa | cut -d " " -f 2)" |
| 66 | node_name: {{ HOSTNAME_CFG01 }} |
| 67 | retry: {count: 1, delay: 5} |
| 68 | skip_fail: false |
| 69 | |
| 70 | {%- endmacro %} |
| 71 | |
| 72 | {%- macro ADD_ROOT_PUB_SSH_TO_MASS() %} |
| 73 | |
| 74 | - description: Generate public from from root private key |
| 75 | cmd: ssh-keygen -y -f ~root/.ssh/id_rsa > ~root/.ssh/id_rsa.pub |
| 76 | node_name: {{ HOSTNAME_CFG01 }} |
| 77 | retry: {count: 1, delay: 5} |
| 78 | skip_fail: false |
| 79 | |
| 80 | - description: Add root public key to MaaS user |
| 81 | cmd: maas mirantis sshkeys create key="$(cat ~root/.ssh/id_rsa.pub)" |
| 82 | node_name: {{ HOSTNAME_CFG01 }} |
| 83 | retry: {count: 1, delay: 5} |
| 84 | skip_fail: false |
| 85 | |
| 86 | {%- endmacro %} |
| 87 | |
| 88 | {%- macro COMMISSION_VMS() %} |
| 89 | |
| 90 | - description: Wait dhcpd server |
| 91 | cmd: timeout 90s /bin/bash -c 'while ! pidof dhcpd; do echo "dhcpd still isnt running"; sleep 10; done' |
| 92 | node_name: {{ HOSTNAME_CFG01 }} |
| 93 | retry: {count: 1, delay: 5} |
| 94 | skip_fail: false |
| 95 | |
| 96 | - description: Add machines and comission |
| 97 | cmd: salt-call state.sls maas.machines |
| 98 | node_name: {{ HOSTNAME_CFG01 }} |
| 99 | retry: {count: 1, delay: 5} |
| 100 | skip_fail: false |
| 101 | |
| 102 | - description: Wait finish of comissioning machines |
| 103 | cmd: salt-call state.sls maas.machines.wait_for_ready |
| 104 | node_name: {{ HOSTNAME_CFG01 }} |
| 105 | retry: {count: 1, delay: 5} |
| 106 | skip_fail: false |
| 107 | |
| 108 | {%- endmacro %} |
| 109 | |
| 110 | {%- macro DEPLOY_VMS() %} |
| 111 | |
| 112 | - description: Show salt keys before deploy |
| 113 | cmd: salt-key |
| 114 | node_name: {{ HOSTNAME_CFG01 }} |
| 115 | retry: {count: 1, delay: 5} |
| 116 | skip_fail: false |
| 117 | |
| 118 | - description: Assign IPs to machines |
| 119 | cmd: salt-call state.sls maas.machines.assign_ip |
| 120 | node_name: {{ HOSTNAME_CFG01 }} |
| 121 | retry: {count: 1, delay: 5} |
| 122 | skip_fail: false |
| 123 | |
| 124 | - description: Assign drive partitions to machines |
| 125 | cmd: salt-call state.sls maas.machines.storage |
| 126 | node_name: {{ HOSTNAME_CFG01 }} |
| 127 | retry: {count: 1, delay: 5} |
| 128 | skip_fail: false |
| 129 | |
| 130 | - description: Deploy machines |
| 131 | cmd: salt-call state.sls maas.machines.deploy |
| 132 | node_name: {{ HOSTNAME_CFG01 }} |
| 133 | retry: {count: 1, delay: 5} |
| 134 | skip_fail: false |
| 135 | |
| 136 | - description: Wait finish of deploying machines |
| 137 | cmd: salt-call state.sls maas.machines.wait_for_deployed |
| 138 | node_name: {{ HOSTNAME_CFG01 }} |
| 139 | retry: {count: 1, delay: 5} |
| 140 | skip_fail: false |
| 141 | |
| 142 | - description: Show salt keys after deploy |
| 143 | cmd: salt-key |
| 144 | node_name: {{ HOSTNAME_CFG01 }} |
| 145 | retry: {count: 1, delay: 5} |
| 146 | skip_fail: false |
| 147 | |
| 148 | - description: Accept salt keys |
| 149 | cmd: salt-key -A -y --include-denied --include-rejected |
| 150 | node_name: {{ HOSTNAME_CFG01 }} |
| 151 | retry: {count: 1, delay: 5} |
| 152 | skip_fail: false |
| 153 | |
| 154 | - description: Show salt keys after accepting |
| 155 | cmd: salt-key |
| 156 | node_name: {{ HOSTNAME_CFG01 }} |
| 157 | retry: {count: 1, delay: 5} |
| 158 | skip_fail: false |
| 159 | |
| 160 | {%- endmacro %} |
| 161 | |
| 162 | {%- macro CONFIG_MACHINES(target) %} |
| 163 | |
| 164 | - description: Refresh pillars |
| 165 | cmd: salt '*' saltutil.refresh_pillar |
| 166 | node_name: {{ HOSTNAME_CFG01 }} |
| 167 | retry: {count: 1, delay: 5} |
| 168 | skip_fail: false |
| 169 | |
| 170 | - description: Sync all |
| 171 | cmd: salt '*' saltutil.sync_all |
| 172 | node_name: {{ HOSTNAME_CFG01 }} |
| 173 | retry: {count: 1, delay: 5} |
| 174 | skip_fail: false |
| 175 | |
| 176 | - description: Show top of reclass |
| 177 | cmd: reclass-salt --top |
| 178 | node_name: {{ HOSTNAME_CFG01 }} |
| 179 | retry: {count: 1, delay: 5} |
| 180 | skip_fail: false |
| 181 | |
| 182 | - description: Set rebooted flag |
| 183 | cmd: salt -C '{{ target }}' cmd.run 'touch /run/is_rebooted' |
| 184 | node_name: {{ HOSTNAME_CFG01 }} |
| 185 | retry: {count: 1, delay: 5} |
| 186 | skip_fail: false |
| 187 | |
| 188 | - description: Config machines and reboot them |
| 189 | cmd: salt --async -C '{{ target }}' cmd.run 'salt-call state.sls linux.system.repo,linux.system.user,openssh,linux.network;reboot' |
| 190 | node_name: {{ HOSTNAME_CFG01 }} |
| 191 | retry: {count: 1, delay: 5} |
| 192 | skip_fail: false |
| 193 | |
| 194 | - description: Wait 10 minutes for machines reboot |
| 195 | cmd: sleep 600 |
| 196 | node_name: {{ HOSTNAME_CFG01 }} |
| 197 | retry: {count: 1, delay: 5} |
| 198 | skip_fail: false |
| 199 | |
| 200 | - description: Check salt minions |
| 201 | cmd: salt -C '{{ target }}' test.ping |
| 202 | node_name: {{ HOSTNAME_CFG01 }} |
| 203 | retry: {count: 5, delay: 30} |
| 204 | skip_fail: false |
| 205 | |
| 206 | - description: Check reboot status of machines |
| 207 | cmd: | |
| 208 | ! salt -C '{{ target }}' cmd.run '[ -f "/run/is_rebooted" ] && echo "Failed" || echo "Rebooted"' | grep -q Failed |
| 209 | node_name: {{ HOSTNAME_CFG01 }} |
| 210 | retry: {count: 1, delay: 5} |
| 211 | skip_fail: false |
| 212 | |
| 213 | {%- endmacro %} |