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