Matteo Scandolo | 3896c47 | 2017-08-01 13:31:42 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 16 | |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 17 | --- |
| 18 | # file: create-lxd/tasks/main.yml |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 19 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 20 | - name: Enable trusty-backports apt repository |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 21 | apt_repository: |
| 22 | repo: "{{ item }}" |
| 23 | state: present |
| 24 | with_items: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 25 | - "deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 26 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 27 | - name: Install LXD from trusty-backports |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 28 | apt: |
| 29 | name: lxd |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 30 | default_release: trusty-backports |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 31 | update_cache: yes |
| 32 | cache_valid_time: 3600 |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 33 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 34 | - name: Create LXD profiles for OpenStack services |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 35 | lxd_profile: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 36 | name: "openstack-{{ item.name }}" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 37 | state: present |
| 38 | config: |
| 39 | user.user-data: | |
| 40 | #cloud-config |
| 41 | ssh_authorized_keys: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 42 | - "{{ lookup('file', ssh_pki_dir ~ '/client_certs/{{ pod_sshkey_name }}_sshkey.pub') }}" |
| 43 | description: 'OpenStack service {{ item.name }} for CORD' |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 44 | devices: |
| 45 | eth0: |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 46 | type: nic |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 47 | parent: mgmtbr |
| 48 | nictype: bridged |
| 49 | # ipv4.address: "{{ mgmt_ipv4_first_octets }}.{{ item.ipv4_last_octet }}" |
| 50 | hwaddr: "{{ item.hwaddr | default(hwaddr_prefix ~ ((mgmt_ipv4_first_octets ~ '.' ~ item.ipv4_last_octet) | ip4_hex)) | hwaddr('unix') }}" |
Andy Bavier | 1cac001 | 2017-03-13 10:06:18 -0400 | [diff] [blame] | 51 | certs: |
| 52 | type: disk |
| 53 | path: /usr/local/share/ca-certificates/cord/ |
| 54 | source: /usr/local/share/ca-certificates/ |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 55 | with_items: "{{ head_lxd_list }}" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 56 | |
| 57 | - name: Create containers for the OpenStack services |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 58 | lxd_container: |
| 59 | name: "{{ item.name }}" |
| 60 | architecture: x86_64 |
| 61 | state: started |
| 62 | source: |
| 63 | type: image |
| 64 | mode: pull |
| 65 | server: https://cloud-images.ubuntu.com/releases |
| 66 | protocol: simplestreams |
| 67 | alias: "{{ ansible_distribution_release }}" |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 68 | profiles: ["openstack-{{ item.name }}"] |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 69 | wait_for_ipv4_addresses: true |
| 70 | timeout: 600 |
| 71 | with_items: "{{ head_lxd_list }}" |
| 72 | |
| 73 | - name: fetch IP of DHCP harvester |
Zack Williams | fe284a1 | 2017-07-01 11:00:04 -0700 | [diff] [blame] | 74 | when: use_maas |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 75 | command: docker-ip harvester |
| 76 | register: harvester_ip |
| 77 | changed_when: False |
| 78 | |
| 79 | - name: force a harvest to get container name resolution |
Zack Williams | fe284a1 | 2017-07-01 11:00:04 -0700 | [diff] [blame] | 80 | when: use_maas |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 81 | uri: |
| 82 | url: http://{{ harvester_ip.stdout }}:8954/harvest |
| 83 | method: POST |
| 84 | |
| 85 | - name: wait for container name resolution |
Zack Williams | fe284a1 | 2017-07-01 11:00:04 -0700 | [diff] [blame] | 86 | when: use_maas |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 87 | host_dns_check: |
| 88 | hosts: "{{ head_lxd_list | map(attribute='name') | list | to_json }}" |
| 89 | command_on_fail: "curl -sS --connect-timeout 3 -XPOST http://{{ harvester_ip.stdout }}:8954/harvest" |
| 90 | register: all_resolved |
| 91 | until: all_resolved.everyone == "OK" |
| 92 | retries: 5 |
| 93 | delay: 10 |
| 94 | failed_when: all_resolved.everyone != "OK" |
| 95 | |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 96 | - name: Wait for containers to be accessible via SSH |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 97 | wait_for: |
Zack Williams | 43d62b5 | 2017-01-23 07:34:45 -0700 | [diff] [blame] | 98 | host: "{{ item.name }}" |
| 99 | port: 22 |
| 100 | search_regex: "OpenSSH" |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 101 | with_items: "{{ head_lxd_list }}" |
| 102 | |
Sapan Bhatia | 35dba66 | 2017-04-18 13:32:28 +0200 | [diff] [blame] | 103 | - name: Ensure /etc/ansible directory exists |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 104 | file: |
| 105 | path: /etc/ansible |
| 106 | state: directory |
| 107 | owner: root |
| 108 | group: root |
| 109 | mode: 0755 |
Sapan Bhatia | 35dba66 | 2017-04-18 13:32:28 +0200 | [diff] [blame] | 110 | |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 111 | - name: Create /etc/ansible/hosts file with containers list |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 112 | template: |
Zack Williams | 5223dd9 | 2017-02-28 23:38:02 -0700 | [diff] [blame] | 113 | src: ansible_hosts.j2 |
| 114 | dest: /etc/ansible/hosts |
| 115 | owner: root |
| 116 | group: root |
| 117 | mode: 0644 |
Andy Bavier | a17d84b | 2016-11-16 09:39:26 -0800 | [diff] [blame] | 118 | |