Ansible deployment of the Kolla containers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.3KB

  1. #!/bin/bash
  2. set -o xtrace
  3. set -o errexit
  4. # Enable unbuffered output for Ansible in Jenkins.
  5. export PYTHONUNBUFFERED=1
  6. GIT_PROJECT_DIR=$(mktemp -d)
  7. function setup_config {
  8. # Use Infra provided pypi.
  9. # Wheel package mirror may be not compatible. So do not enable it.
  10. PIP_CONF=$(mktemp)
  11. cat > ${PIP_CONF} <<EOF
  12. [global]
  13. timeout = 60
  14. index-url = $NODEPOOL_PYPI_MIRROR
  15. trusted-host = $NODEPOOL_MIRROR_HOST
  16. EOF
  17. echo "RUN echo $(base64 -w0 ${PIP_CONF}) | base64 -d > /etc/pip.conf" | sudo tee /etc/kolla/header
  18. rm ${PIP_CONF}
  19. if [[ $ACTION != "bifrost" ]]; then
  20. GATE_IMAGES="cron,fluentd,glance,haproxy,keepalived,keystone,kolla-toolbox,mariadb,memcached,neutron,nova,openvswitch,rabbitmq,horizon,chrony,heat,placement"
  21. else
  22. GATE_IMAGES="bifrost"
  23. fi
  24. if [[ $ACTION =~ "ceph" ]]; then
  25. GATE_IMAGES+=",ceph,cinder"
  26. fi
  27. if [[ $ACTION == "cinder-lvm" ]]; then
  28. GATE_IMAGES+=",cinder,iscsid,tgtd"
  29. fi
  30. if [[ $ACTION == "zun" ]]; then
  31. GATE_IMAGES+=",zun,kuryr,etcd"
  32. fi
  33. if [[ $ACTION == "scenario_nfv" ]]; then
  34. GATE_IMAGES+=",tacker,mistral,redis,barbican"
  35. fi
  36. if [[ $ACTION == "ironic" ]]; then
  37. GATE_IMAGES+=",dnsmasq,ironic,iscsid"
  38. fi
  39. cat <<EOF | sudo tee /etc/kolla/kolla-build.conf
  40. [DEFAULT]
  41. include_header = /etc/kolla/header
  42. namespace = lokolla
  43. base = ${BASE_DISTRO}
  44. install_type = ${INSTALL_TYPE}
  45. tag = ${TAG}
  46. profile = gate
  47. registry = 127.0.0.1:4000
  48. push = true
  49. logs_dir = /tmp/logs/build
  50. [profiles]
  51. gate = ${GATE_IMAGES}
  52. EOF
  53. mkdir -p /tmp/logs/build
  54. if [[ "${DISTRO}" == "Debian" ]]; then
  55. # Infra does not sign their mirrors so we ignore gpg signing in the gate
  56. echo "RUN echo 'APT::Get::AllowUnauthenticated \"true\";' > /etc/apt/apt.conf" | sudo tee -a /etc/kolla/header
  57. # Optimize the repos to take advantage of the Infra provided mirrors for Ubuntu
  58. cat << EOF | sudo tee -a /etc/kolla/kolla-build.conf
  59. apt_sources_list = /etc/kolla/sources.list
  60. EOF
  61. sudo cp /etc/apt/sources.list /etc/kolla/sources.list
  62. sudo cat /etc/apt/sources.list.available.d/ubuntu-cloud-archive-pike.list | sudo tee -a /etc/kolla/sources.list
  63. # Append non-infra provided repos to list
  64. cat << EOF | sudo tee -a /etc/kolla/sources.list
  65. deb http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.0/ubuntu xenial main
  66. deb http://repo.percona.com/apt xenial main
  67. deb http://packages.elastic.co/elasticsearch/2.x/debian stable main
  68. deb http://packages.elastic.co/kibana/4.6/debian stable main
  69. EOF
  70. fi
  71. }
  72. function detect_distro {
  73. DISTRO=$(ansible all -i "localhost," -msetup -clocal | awk -F\" '/ansible_os_family/ {print $4}')
  74. }
  75. function setup_ansible {
  76. RAW_INVENTORY=/etc/kolla/inventory
  77. # TODO(SamYaple): Move to virtualenv
  78. sudo -H pip install -U "ansible>=2.4" "docker>=2.0.0" "python-openstackclient" "ara<1.0.0" "cmd2<0.9.0"
  79. if [[ $ACTION == "zun" ]]; then
  80. sudo -H pip install -U "python-zunclient"
  81. fi
  82. if [[ $ACTION == ironic ]]; then
  83. # NOTE(mgoddard): Installing python-ironicclient to site-packages fails
  84. # due to pip 10 distutils issue with ipaddress package.
  85. virtualenv ~/ironic-venv
  86. ~/ironic-venv/bin/pip install -U pip
  87. ~/ironic-venv/bin/pip install python-openstackclient python-ironicclient
  88. fi
  89. detect_distro
  90. sudo mkdir /etc/ansible
  91. ara_location=$(python -m ara.setup.callback_plugins)
  92. sudo tee /etc/ansible/ansible.cfg<<EOF
  93. [defaults]
  94. callback_plugins = ${ara_location}
  95. host_key_checking = False
  96. EOF
  97. # Record the running state of the environment as seen by the setup module
  98. ansible all -i ${RAW_INVENTORY} -e ansible_user=$USER -m setup > /tmp/logs/ansible/initial-setup
  99. }
  100. function setup_node {
  101. ansible-playbook -i ${RAW_INVENTORY} -e ansible_user=$USER tools/playbook-setup-nodes.yml
  102. }
  103. function prepare_images {
  104. if [[ "${BUILD_IMAGE}" == "False" ]]; then
  105. return
  106. fi
  107. sudo docker run -d -p 4000:5000 --restart=always -v /opt/kolla_registry/:/var/lib/registry --name registry registry:2
  108. pushd "${KOLLA_SRC_DIR}"
  109. sudo tox -e "build-${BASE_DISTRO}-${INSTALL_TYPE}"
  110. popd
  111. }
  112. setup_ansible
  113. setup_config
  114. setup_node
  115. tools/kolla-ansible -i ${RAW_INVENTORY} -e ansible_user=$USER bootstrap-servers > /tmp/logs/ansible/bootstrap-servers
  116. prepare_images