Dennis Dmitriev | eea5bb3 | 2017-09-03 23:20:54 +0300 | [diff] [blame] | 1 | {% from 'cookied-mcp-ocata-dvr-vxlan/underlay.yaml' import HOSTNAME_CFG01 with context %} |
| 2 | {% from 'cookied-mcp-ocata-dvr-vxlan/underlay.yaml' import LAB_CONFIG_NAME with context %} |
| 3 | {% from 'cookied-mcp-ocata-dvr-vxlan/underlay.yaml' import DOMAIN_NAME with context %} |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 4 | |
| 5 | {% set SALT_MODELS_REPOSITORY = os_env('SALT_MODELS_REPOSITORY','https://gerrit.mcp.mirantis.net/salt-models/mcp-virtual-lab') %} |
| 6 | # Other salt model repository parameters see in shared-salt.yaml |
| 7 | |
| 8 | # Name of the context file (without extension, that is fixed .yaml) used to render the Environment model |
| 9 | {% set ENVIRONMENT_MODEL_INVENTORY_NAME = os_env('ENVIRONMENT_MODEL_INVENTORY_NAME','virtual-devops-mcp-ocata-sl2') %} |
| 10 | |
| 11 | |
| 12 | {% import 'shared-salt.yaml' as SHARED with context %} |
| 13 | |
| 14 | {{ SHARED.MACRO_INSTALL_SALT_MASTER() }} |
| 15 | |
| 16 | |
| 17 | {#{ SHARED.MACRO_CLONE_RECLASS_MODELS() }#} |
| 18 | - description: Create cluster model from cookiecutter templates |
| 19 | cmd: | |
| 20 | set -e; |
| 21 | pip install cookiecutter |
| 22 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/mk/cookiecutter-templates /tmp/cookiecutter-templates |
| 23 | mkdir -p /srv/salt/reclass/classes/cluster/ |
| 24 | mkdir -p /srv/salt/reclass/classes/system/ |
| 25 | mkdir -p /srv/salt/reclass/classes/service/ |
| 26 | mkdir -p /srv/salt/reclass/nodes/ |
| 27 | |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 28 | {%- set CONTEXT_PATH = '/tmp/cookiecutter-templates/contexts/openstack_ovs_dvr_vxlan.yml' %} |
| 29 | |
| 30 | # Override some context parameters |
| 31 | sed -i 's/cluster_name:.*/cluster_name: {{ LAB_CONFIG_NAME }}/g' {{ CONTEXT_PATH }} |
| 32 | sed -i 's/cluster_domain:.*/cluster_domain: {{ DOMAIN_NAME }}/g' {{ CONTEXT_PATH }} |
| 33 | sed -i 's/control_vlan:.*/control_vlan: \"2416\"/g' {{ CONTEXT_PATH }} |
| 34 | sed -i 's/tenant_vlan:.*/tenant_vlan: \"2417\"/g' {{ CONTEXT_PATH }} |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 35 | |
Dennis Dmitriev | 910a800 | 2017-08-31 14:53:47 +0300 | [diff] [blame] | 36 | # Temporary workaround (with hardcoded address .90 -> .15) of bug https://mirantis.jira.com/browse/PROD-14377 |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 37 | sed -i 's/salt_master_address:.*/salt_master_address: {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.15/g' {{ CONTEXT_PATH }} |
| 38 | sed -i 's/salt_master_management_address:.*/salt_master_management_address: {{ SHARED.IPV4_NET_ADMIN_PREFIX }}.15/g' {{ CONTEXT_PATH }} |
Dennis Dmitriev | 910a800 | 2017-08-31 14:53:47 +0300 | [diff] [blame] | 39 | |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 40 | # Replace firstly to an intermediate value to avoid intersection between |
| 41 | # already replaced and replacing networks. |
| 42 | # For example, if generated IPV4_NET_ADMIN_PREFIX=10.16.0 , then there is a risk of replacing twice: |
| 43 | # 192.168.10 -> 10.16.0 (generated network for admin) |
| 44 | # 10.16.0 -> <external network> |
| 45 | # So let's replace constant networks to the keywords, and then keywords to the desired networks. |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 46 | sed -i 's/10\.167\.5/==IPV4_NET_ADMIN_PREFIX==/g' {{ CONTEXT_PATH }} |
| 47 | sed -i 's/10\.167\.4/==IPV4_NET_CONTROL_PREFIX==/g' {{ CONTEXT_PATH }} |
| 48 | sed -i 's/10\.167\.6/==IPV4_NET_TENANT_PREFIX==/g' {{ CONTEXT_PATH }} |
| 49 | sed -i 's/172\.17\.16\./==IPV4_NET_EXTERNAL_PREFIX==/g' {{ CONTEXT_PATH }} |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 50 | |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 51 | sed -i 's/==IPV4_NET_ADMIN_PREFIX==/{{ SHARED.IPV4_NET_ADMIN_PREFIX }}/g' {{ CONTEXT_PATH }} |
| 52 | sed -i 's/==IPV4_NET_CONTROL_PREFIX==/{{ SHARED.IPV4_NET_CONTROL_PREFIX }}/g' {{ CONTEXT_PATH }} |
| 53 | sed -i 's/==IPV4_NET_TENANT_PREFIX==/{{ SHARED.IPV4_NET_TENANT_PREFIX }}/g' {{ CONTEXT_PATH }} |
| 54 | sed -i 's/==IPV4_NET_EXTERNAL_PREFIX==/{{ SHARED.IPV4_NET_EXTERNAL_PREFIX }}./g' {{ CONTEXT_PATH }} |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 55 | |
| 56 | for i in $(ls /tmp/cookiecutter-templates/cluster_product/); do |
| 57 | cookiecutter /tmp/cookiecutter-templates/cluster_product/$i \ |
Dennis Dmitriev | 0496eb7 | 2017-09-05 21:42:10 +0300 | [diff] [blame] | 58 | --config-file {{ CONTEXT_PATH }} \ |
Dennis Dmitriev | 9dada8a | 2017-08-30 17:38:55 +0300 | [diff] [blame] | 59 | --output-dir /srv/salt/reclass/classes/cluster/ \ |
| 60 | --no-input -f; |
| 61 | done |
| 62 | |
| 63 | export GIT_SSL_NO_VERIFY=true; git clone https://gerrit.mcp.mirantis.net/salt-models/reclass-system /srv/salt/reclass/classes/system/ |
| 64 | |
| 65 | # Create the cfg01 node and disable checkouting the model from remote repository |
| 66 | cat << 'EOF' >> /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml |
| 67 | classes: |
| 68 | - cluster.{{ LAB_CONFIG_NAME }}.infra.config |
| 69 | parameters: |
| 70 | _param: |
| 71 | linux_system_codename: xenial |
| 72 | reclass_data_revision: master |
| 73 | linux: |
| 74 | system: |
| 75 | name: cfg01 |
| 76 | domain: {{ DOMAIN_NAME }} |
| 77 | # local storage |
| 78 | reclass: |
| 79 | storage: |
| 80 | data_source: |
| 81 | engine: local |
| 82 | EOF |
| 83 | |
| 84 | node_name: {{ HOSTNAME_CFG01 }} |
| 85 | retry: {count: 1, delay: 1} |
| 86 | skip_fail: false |
| 87 | |
| 88 | - description: Modify cluster model for testing purposes |
| 89 | cmd: | |
| 90 | set -e; |
| 91 | apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev; |
| 92 | pip install git+https://github.com/dis-xcom/reclass-tools; |
| 93 | |
| 94 | # Enable 'root' user |
| 95 | reclass-tools add-key classes system.openssh.server.team.lab /srv/salt/reclass/classes/cluster/{{ LAB_CONFIG_NAME }}/infra/config.yml --merge |
| 96 | |
| 97 | node_name: {{ HOSTNAME_CFG01 }} |
| 98 | retry: {count: 1, delay: 1} |
| 99 | skip_fail: false |
| 100 | |
| 101 | |
| 102 | {{ SHARED.MACRO_CONFIGURE_RECLASS(FORMULA_SERVICES='"linux" "reclass" "salt" "openssh" "ntp" "git" "nginx" "collectd" "sensu" "heka" "sphinx" "keystone" "mysql" "grafana" "haproxy" "rsyslog" "horizon" "prometheus" "telegraf" "elasticsearch" "powerdns" "glusterfs" "xtrabackup"') }} |
| 103 | |
| 104 | |
| 105 | - description: Upload 'environment' to {{ HOSTNAME_GTW01 }} |
| 106 | upload: |
| 107 | local_path: {{ config.salt_deploy.environment_template_dir }} |
| 108 | remote_path: /tmp/environment/ |
| 109 | node_name: {{ HOSTNAME_CFG01 }} |
| 110 | skip_fail: false |
| 111 | |
| 112 | - description: "[EXPERIMENTAL] Create environment model for virtual environment" |
| 113 | cmd: | |
| 114 | set -e; |
| 115 | ln -s '/tmp/environment/environment_template/{{ '{# interfaces #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/'; |
| 116 | ln -s '/tmp/environment/environment_template/{{ '{# roles #}' }}' '/tmp/environment/environment_template/{{ '{{ cookiecutter._env_name }}' }}/'; |
| 117 | reclass-tools render --template-dir /tmp/environment/environment_template/ \ |
| 118 | --output-dir /srv/salt/reclass/classes/environment/ \ |
| 119 | --context /tmp/environment/environment_inventory/{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}.yaml \ |
| 120 | --env-name {{ ENVIRONMENT_MODEL_INVENTORY_NAME }} |
| 121 | node_name: {{ HOSTNAME_CFG01 }} |
| 122 | retry: {count: 1, delay: 5} |
| 123 | skip_fail: false |
| 124 | |
| 125 | - description: "[EXPERIMENTAL] Remove linux.network.interface object from the cluster/system models and use fixed 'environment' model instead" |
| 126 | cmd: | |
| 127 | apt-get -y install python-virtualenv python-pip build-essential python-dev libssl-dev; |
| 128 | pip install git+https://github.com/dis-xcom/reclass-tools; |
| 129 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/cluster/; |
| 130 | reclass-tools del-key parameters.linux.network.interface /srv/salt/reclass/classes/system/; |
| 131 | reclass-tools del-key parameters.linux.network.interface /usr/share/salt-formulas/reclass/; |
| 132 | |
| 133 | if ! reclass-tools get-key 'classes' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml | grep -q "environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}$"; then |
| 134 | reclass-tools add-key 'classes' 'environment.{{ ENVIRONMENT_MODEL_INVENTORY_NAME }}' /srv/salt/reclass/nodes/{{ HOSTNAME_CFG01 }}.yml --merge ; |
| 135 | fi; |
| 136 | |
| 137 | node_name: {{ HOSTNAME_CFG01 }} |
| 138 | retry: {count: 1, delay: 5} |
| 139 | skip_fail: false |
| 140 | |
| 141 | {{ SHARED.MACRO_INSTALL_SALT_MINIONS() }} |
| 142 | |
| 143 | {{ SHARED.MACRO_RUN_SALT_MASTER_UNDERLAY_STATES() }} |
| 144 | |
| 145 | {{ SHARED.MACRO_GENERATE_INVENTORY() }} |
| 146 | |
| 147 | {{ SHARED.MACRO_NETWORKING_WORKAROUNDS() }} |
| 148 | |
| 149 | {{ SHARED.MACRO_BOOTSTRAP_ALL_MINIONS() }} |
| 150 | |
| 151 | #- description: Hack gtw node |
| 152 | # cmd: salt 'gtw*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.110/24 dev ens4; ip addr flush dev ens4"; |
| 153 | # node_name: {{ HOSTNAME_CFG01 }} |
| 154 | # retry: {count: 1, delay: 10} |
| 155 | # skip_fail: false |
| 156 | |
| 157 | #- description: Hack cmp01 node |
| 158 | # cmd: salt 'cmp01*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.105/24 dev ens4; ip addr flush dev ens4"; |
| 159 | # node_name: {{ HOSTNAME_CFG01 }} |
| 160 | # retry: {count: 1, delay: 10} |
| 161 | # skip_fail: false |
| 162 | |
| 163 | #- description: Hack cmp02 node |
| 164 | # cmd: salt 'cmp02*' cmd.run "ip addr del {{ SHARED.IPV4_NET_CONTROL_PREFIX }}.106/24 dev ens4; ip addr flush dev ens4"; |
| 165 | # node_name: {{ HOSTNAME_CFG01 }} |
| 166 | # retry: {count: 1, delay: 10} |
| 167 | # skip_fail: false |