Fatih Degirmenci | fef711b | 2020-05-19 11:27:40 +0000 | [diff] [blame^] | 1 | --- |
| 2 | # ============LICENSE_START======================================================= |
| 3 | # Copyright (C) 2019 The Nordix Foundation. All rights reserved. |
| 4 | # ================================================================================ |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # SPDX-License-Identifier: Apache-2.0 |
| 18 | # ============LICENSE_END========================================================= |
| 19 | |
| 20 | # we need the public IP of the jumphost so we can check if it is reachable |
| 21 | - name: Get public IP of jumphost from openstack stack output |
| 22 | command: "openstack stack output show {{ heat_stack_name }} jumphost_public_ip -c output_value -f json" |
| 23 | register: stack_output |
| 24 | changed_when: false |
| 25 | until: "'output_value' in stack_output.stdout" |
| 26 | retries: 10 |
| 27 | delay: 3 |
| 28 | environment: |
| 29 | PATH: "{{ engine_venv }}/bin" |
| 30 | delegate_to: localhost |
| 31 | run_once: true |
| 32 | |
| 33 | - name: Set public IP of jumphost |
| 34 | set_fact: |
| 35 | jumphost_public_ip: "{{ stack_output.stdout }}" |
| 36 | |
| 37 | - name: Log jumphost public IP to console |
| 38 | debug: |
| 39 | msg: "Jumphost public IP is {{ jumphost_public_ip.output_value[0] }}" |
| 40 | delegate_to: localhost |
| 41 | run_once: true |
| 42 | |
| 43 | - name: Wait for jumphost to be reachable via SSH |
| 44 | wait_for: |
| 45 | host: "{{ jumphost_public_ip.output_value[0] }}" |
| 46 | port: 22 |
| 47 | state: started |
| 48 | delay: 15 |
| 49 | connect_timeout: 10 |
| 50 | timeout: 1000 |
| 51 | delegate_to: localhost |
| 52 | |
| 53 | - name: Copy SSH keys to jumphost for target node access |
| 54 | copy: |
| 55 | src: "{{ item }}" |
| 56 | dest: "/root/.ssh/" |
| 57 | owner: "root" |
| 58 | group: "root" |
| 59 | mode: 0600 |
| 60 | with_items: |
| 61 | - "/home/{{ local_user }}/.ssh/id_rsa" |
| 62 | - "/home/{{ local_user }}/.ssh/id_rsa.pub" |
| 63 | |
| 64 | # NOTE (fdegir): it looks like the provisioner is the best place |
| 65 | # to prepare for offline deployments as the way things done for |
| 66 | # OpenStack based deployments are heavily dependend on the provisioner |
| 67 | # so we transfer the dependencies to jumphost here and update apt |
| 68 | # sources.list as well to ensure the rest of the provisioning and |
| 69 | # installation process stays as is |
| 70 | - block: |
| 71 | - name: Update /etc/hosts with server FQDN |
| 72 | lineinfile: |
| 73 | path: /etc/hosts |
| 74 | regex: '^127\.0\.0\.1' |
| 75 | line: "127.0.0.1 localhost {{ server_fqdn }}" |
| 76 | |
| 77 | - name: Ensure /opt/engine exists and empty |
| 78 | file: |
| 79 | path: /opt/engine |
| 80 | state: absent |
| 81 | force: true |
| 82 | with_items: |
| 83 | - absent |
| 84 | - directory |
| 85 | ignore_errors: true |
| 86 | |
| 87 | # NOTE (fdegir): we need dependencies available on jumphost |
| 88 | # before we continue with the rest of the process |
| 89 | - name: Synchronize dependencies with jumphost |
| 90 | synchronize: |
| 91 | src: /opt/engine/offline |
| 92 | dest: /opt/engine |
| 93 | recursive: true |
| 94 | delete: true |
| 95 | |
| 96 | - name: Update /etc/apt/sources.list to use local apt repository |
| 97 | template: |
| 98 | src: sources.list.j2 |
| 99 | dest: /etc/apt/sources.list |
| 100 | owner: root |
| 101 | group: root |
| 102 | mode: '0644' |
| 103 | backup: true |
| 104 | when: execution_mode == "offline-deployment" |
| 105 | |
| 106 | # NOTE (fdegir): the python dependencies except python itself may not be |
| 107 | # available on the instances created on OpenStack so we install them here |
| 108 | # to ensure the rest of the process does not bother with them |
| 109 | - name: Install python dependencies |
| 110 | action: | |
| 111 | {{ ansible_pkg_mgr }} name={{ item }} state=present update_cache=true |
| 112 | with_items: |
| 113 | - "python3-pip" |
| 114 | - "python3-setuptools" |
| 115 | - "python3-virtualenv" |
| 116 | |
| 117 | # vim: set ts=2 sw=2 expandtab: |