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