Zack Williams | 2f5f2bd | 2017-12-01 15:04:22 -0700 | [diff] [blame] | 1 | --- |
Matteo Scandolo | 3896c47 | 2017-08-01 13:31:42 -0700 | [diff] [blame] | 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 16 | # file: create-lxd/tasks/main.yml |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 17 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 18 | - name: Enable trusty-backports apt repository |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 19 | apt_repository: |
| 20 | repo: "{{ item }}" |
| 21 | state: present |
| 22 | with_items: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 23 | - "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 24 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 25 | - name: Install LXD from trusty-backports |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 26 | apt: |
| 27 | name: lxd |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 28 | default_release: trusty-backports |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 29 | update_cache: yes |
| 30 | cache_valid_time: 3600 |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 31 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 32 | - name: Create LXD profiles for OpenStack services |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 33 | lxd_profile: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 34 | name: "openstack-{{ item.name }}" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 35 | state: present |
| 36 | config: |
| 37 | user.user-data: | |
| 38 | #cloud-config |
| 39 | ssh_authorized_keys: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 40 | - "{{ lookup('file', ssh_pki_dir ~ '/client_certs/{{ pod_sshkey_name }}_sshkey.pub') }}" |
| 41 | description: 'OpenStack service {{ item.name }} for CORD' |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 42 | devices: |
| 43 | eth0: |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 44 | type: nic |
Zack Williams | 2f5f2bd | 2017-12-01 15:04:22 -0700 | [diff] [blame] | 45 | parent: "{{ management_net_bridge }}" |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 46 | nictype: bridged |
Zack Williams | 6e1d816 | 2018-01-31 15:29:55 -0700 | [diff] [blame] | 47 | hwaddr: "{{ item.hwaddr | default( vtn_net_management_host_hwaddr_prefix ~ ( vtn_net_management_host_cidr | ipaddr(item.ipv4_last_octet) | ipaddr('address') | ip4_hex )) | hwaddr('linux') }}" |
Andy Bavier | 1cac001 | 2017-03-13 10:06:18 -0400 | [diff] [blame] | 48 | certs: |
| 49 | type: disk |
| 50 | path: /usr/local/share/ca-certificates/cord/ |
| 51 | source: /usr/local/share/ca-certificates/ |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 52 | with_items: "{{ head_lxd_list }}" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 53 | |
| 54 | - name: Create containers for the OpenStack services |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 55 | lxd_container: |
| 56 | name: "{{ item.name }}" |
| 57 | architecture: x86_64 |
| 58 | state: started |
| 59 | source: |
| 60 | type: image |
| 61 | mode: pull |
| 62 | server: https://cloud-images.ubuntu.com/releases |
| 63 | protocol: simplestreams |
| 64 | alias: "{{ ansible_distribution_release }}" |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 65 | profiles: ["openstack-{{ item.name }}"] |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 66 | wait_for_ipv4_addresses: true |
| 67 | timeout: 600 |
| 68 | with_items: "{{ head_lxd_list }}" |
| 69 | |
| 70 | - name: fetch IP of DHCP harvester |
Zack Williams | fe284a1 | 2017-07-01 11:00:04 -0700 | [diff] [blame] | 71 | when: use_maas |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 72 | command: docker-ip harvester |
| 73 | register: harvester_ip |
| 74 | changed_when: False |
| 75 | |
| 76 | - name: force a harvest to get container name resolution |
Zack Williams | fe284a1 | 2017-07-01 11:00:04 -0700 | [diff] [blame] | 77 | when: use_maas |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 78 | uri: |
| 79 | url: http://{{ harvester_ip.stdout }}:8954/harvest |
| 80 | method: POST |
| 81 | |
| 82 | - name: wait for container name resolution |
Zack Williams | fe284a1 | 2017-07-01 11:00:04 -0700 | [diff] [blame] | 83 | when: use_maas |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 84 | host_dns_check: |
| 85 | hosts: "{{ head_lxd_list | map(attribute='name') | list | to_json }}" |
| 86 | command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest" |
| 87 | register: all_resolved |
| 88 | until: all_resolved.everyone == "OK" |
| 89 | retries: 5 |
| 90 | delay: 10 |
| 91 | failed_when: all_resolved.everyone != "OK" |
| 92 | |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 93 | - name: Wait for containers to be accessible via SSH |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 94 | wait_for: |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 95 | host: "{{ item.name }}" |
| 96 | port: 22 |
| 97 | search_regex: "OpenSSH" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 98 | with_items: "{{ head_lxd_list }}" |
| 99 | |
Sapan Bhatia | 35dba66 | 2017-04-18 13:32:28 +0200 | [diff] [blame] | 100 | - name: Ensure /etc/ansible directory exists |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 101 | file: |
| 102 | path: /etc/ansible |
| 103 | state: directory |
| 104 | owner: root |
| 105 | group: root |
| 106 | mode: 0755 |
Sapan Bhatia | 35dba66 | 2017-04-18 13:32:28 +0200 | [diff] [blame] | 107 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 108 | - name: Create /etc/ansible/hosts file with containers list |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 109 | template: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 110 | src: ansible_hosts.j2 |
| 111 | dest: /etc/ansible/hosts |
| 112 | owner: root |
| 113 | group: root |
| 114 | mode: 0644 |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 115 | |