Update the LXC container create role
The LXC container create role has not been updated to use some of our more well throughout patterns and layouts. This change updates the role so that its following our normal role conventions and simplifying task execution. New tags have been added to follow the basic tag pattern found in all other roles. The two tags now supported are lxc-config, and lxc-create. The creation backends have been seperated out into dynamically included files. This will reduce our "skips" which will improve execution time and assist developers in understanding what is happening when a container is created. Stubbs for BTRFS and ZFS container types have been added so future work can continue on those two store options without impacting our normal workflow. All task files have been updated to use the "lxc_" prefix which follows the pattern found in everyone of our roles. Change-Id: I0982a42321cf88f66442b5f766729f17c68e8e4a Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
This commit is contained in:
parent
8378c65c62
commit
3c22200109
@ -70,11 +70,18 @@ lxc_container_rootfs_directory: "{{ lxc_container_directory }}/{{ container_name
|
||||
lxc_container_fs_size: 5G
|
||||
lxc_container_fs_type: ext4
|
||||
|
||||
# The container creation process now allows ``copy-on-write`` to be set as
|
||||
# the ``lxc_container_backing_method`` when the
|
||||
# ``lxc_container_backing_store`` is set to ``lvm``. When this is set it
|
||||
# will use a snapshot of the base container to build the containers.
|
||||
lxc_container_backing_method: null
|
||||
|
||||
# The container backing store can be set to 'overlayfs' to use overlayfs
|
||||
# This should only be done for production use with a linux kernel > 3.14
|
||||
# which is when overlayfs was merged into the mainline kernel.
|
||||
# lxc_container_backing_store: overlayfs
|
||||
# Other store options are "dir" and "lvm".
|
||||
# Other store options are: ["btrfs", "dir", "zfs", "lvm"].
|
||||
lxc_container_backing_store: dir
|
||||
|
||||
# If the container backing store is LVM, the automatic detection will
|
||||
# require the presence of the lxc_container_vg_name volume group. If
|
||||
|
@ -0,0 +1,21 @@
|
||||
---
|
||||
features:
|
||||
- The tag options when creating an LXC container have been simplified. The two
|
||||
tags now supported by the `lxc_container_create` role are
|
||||
**lxc-{create,config}**.
|
||||
upgrade:
|
||||
- The LXC container create option `lxc_container_backing_store` is now defined
|
||||
by default and has a value of "dir". Prior to this release the backend store
|
||||
option was using several auto-detection methods to try and guess the store
|
||||
type based on facts fed into the role and derived from the physical host.
|
||||
While the auto-detection methods worked, they created a cumbersome set of
|
||||
conditionals and limited our ability to leverage additional container
|
||||
stores. Having this option be a default allows deployers to mix and match
|
||||
container stores to suit the needs of the deployment. Existing deployments
|
||||
should set this option within group or user variables to ensure
|
||||
there's no change in the backend store when new container be provisioned.
|
||||
other:
|
||||
- The LXC container create role will now check for the LXC volume group if
|
||||
the option `lxc_container_backing_store` is set to "lvm". If this volume
|
||||
group is not found, the role will halt and instruct the deployer to update
|
||||
their configuration options and inspect their host setup.
|
@ -13,155 +13,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- name: Read custom facts from previous runs
|
||||
setup:
|
||||
filter: ansible_local
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Check for lxc volume group
|
||||
shell: "(which vgs > /dev/null && vgs | grep -o '{{ lxc_container_vg_name }}') || false"
|
||||
register: vg_result
|
||||
failed_when: false
|
||||
changed_when: vg_result.rc != 0
|
||||
delegate_to: "{{ physical_host }}"
|
||||
when: lxc_container_backing_store is not defined or lxc_container_backing_store == "lvm"
|
||||
tags:
|
||||
- lxc_container_create-vg-detect
|
||||
|
||||
- name: Set container backend to "dir" or "lvm" based on whether the lxc VG was found
|
||||
set_fact:
|
||||
lxc_container_backing_store: "{{ (vg_result.rc != 0) | ternary('dir', 'lvm') }}"
|
||||
when: vg_result.rc is defined
|
||||
tags:
|
||||
- lxc_container_create-vg-detect
|
||||
|
||||
- name: Container service directories
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: "directory"
|
||||
with_items:
|
||||
- "/openstack/{{ inventory_hostname }}"
|
||||
- "/openstack/backup/{{ inventory_hostname }}"
|
||||
- "/openstack/log/{{ inventory_hostname }}"
|
||||
- "{{ lxc_container_directory }}/{{ inventory_hostname }}"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-directories
|
||||
|
||||
- name: LXC autodev setup
|
||||
template:
|
||||
src: "autodev.j2"
|
||||
dest: "/var/lib/lxc/{{ inventory_hostname }}/autodev"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0755"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-autodev
|
||||
|
||||
- name: Create container
|
||||
lxc_container:
|
||||
name: "{{ inventory_hostname }}"
|
||||
container_log: true
|
||||
container_log_level: "{{ (debug | bool) | ternary('DEBUG', 'INFO') }}"
|
||||
config: "{{ lxc_container_config }}"
|
||||
template: "{{ lxc_container_template }}"
|
||||
state: started
|
||||
backing_store: "{{ lxc_container_backing_store }}"
|
||||
directory: "{{ lxc_container_rootfs_directory }}"
|
||||
fs_size: "{{ properties.container_fs_size | default(lxc_container_fs_size) }}"
|
||||
fs_type: "{{ lxc_container_fs_type }}"
|
||||
vg_name: "{{ lxc_container_vg_name }}"
|
||||
template_options: "{{ lxc_container_download_template_options }}"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
when: >
|
||||
lxc_container_backing_store != "overlayfs" or
|
||||
(lxc_container_backing_store == 'lvm' and not
|
||||
(lxc_container_backing_method is defined
|
||||
and lxc_container_backing_method == 'copy-on-write'))
|
||||
tags:
|
||||
- lxc_container_create-create
|
||||
|
||||
# Due to https://github.com/ansible/ansible-modules-extras/issues/2577 the
|
||||
# next two tasks do not use the lxc_container module.
|
||||
# TODO(odyssey4me): Revisit this once a fix has merged
|
||||
- name: Check if container exists (copy-on-write backing store)
|
||||
command: "lxc-info -n {{ inventory_hostname }}"
|
||||
failed_when: false
|
||||
delegate_to: "{{ physical_host }}"
|
||||
register: lxc_container_info
|
||||
when: >
|
||||
lxc_container_backing_store == "overlayfs" or
|
||||
(lxc_container_backing_store == 'lvm' and
|
||||
lxc_container_backing_method is defined and
|
||||
lxc_container_backing_method == 'copy-on-write')
|
||||
|
||||
# Due to https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1591510
|
||||
# the '-B' option is used, instead of the more understandable
|
||||
# '--backingstore'.
|
||||
# TODO(odyssey4me): Revisit this once a fix has merged
|
||||
# NOTE(hwoarang) lxc-copy is only available since lxc-2.0.0 so emulate
|
||||
# its behavior using the old lxc-clone command. This is only a problem
|
||||
# on openSUSE so it's safe to remove it when lxc-2.X becomes the default
|
||||
# option for openSUSE in the openstack-ansible-lxc_hosts role.
|
||||
- block:
|
||||
- name: Create container (copy-on-write backing store)
|
||||
command: >
|
||||
lxc-copy --snapshot -B {{ lxc_container_backing_store }}
|
||||
--name {{ lxc_container_base_name }}
|
||||
--newname {{ inventory_hostname }}
|
||||
-L {{ properties.container_fs_size | default(lxc_container_fs_size) }}
|
||||
--logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
|
||||
--logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }}
|
||||
delegate_to: "{{ physical_host }}"
|
||||
rescue:
|
||||
# NOTE(hwoarang) lxc-clone does not support the common
|
||||
# --logfile/logpriority options so we just redirect everything to the log
|
||||
# which is probably the best we can do.
|
||||
- name: Create container (copy-on-write backing store) (fallback)
|
||||
shell: >
|
||||
lxc-clone -s -B {{ lxc_container_backing_store }} -L {{ properties.container_fs_size | default(lxc_container_fs_size) }}
|
||||
{{ lxc_container_base_name }} {{ inventory_hostname }} &>>
|
||||
{{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
|
||||
delegate_to: "{{ physical_host }}"
|
||||
|
||||
when: >
|
||||
(lxc_container_backing_store == "overlayfs" or
|
||||
(lxc_container_backing_store == 'lvm' and
|
||||
lxc_container_backing_method is defined and
|
||||
lxc_container_backing_method == 'copy-on-write')) and
|
||||
lxc_container_info.rc != 0
|
||||
tags:
|
||||
- lxc_container_create-create
|
||||
|
||||
- name: Check container state
|
||||
command: "lxc-info -n {{ inventory_hostname }} --state"
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
delegate_to: "{{ physical_host }}"
|
||||
register: _lxc_container_state
|
||||
|
||||
# Due to https://github.com/ansible/ansible-modules-extras/issues/2691
|
||||
# this uses the LXC CLI tools to ensure that we get logging.
|
||||
# TODO(odyssey4me): revisit this once the bug is fixed and released
|
||||
- name: Start the container if it is not already running
|
||||
command: >
|
||||
lxc-start --daemon --name {{ inventory_hostname }}
|
||||
--logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
|
||||
--logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }}
|
||||
delegate_to: "{{ physical_host }}"
|
||||
when: _lxc_container_state.stdout.find('STOPPED') != -1
|
||||
|
||||
- name: Execute container commands
|
||||
lxc_container:
|
||||
name: "{{ inventory_hostname }}"
|
||||
container_command: |
|
||||
{{ lxc_container_commands }}
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-commands
|
||||
|
||||
- name: Write default container config
|
||||
lineinfile:
|
||||
@ -172,8 +29,6 @@
|
||||
delegate_to: "{{ physical_host }}"
|
||||
notify:
|
||||
- Lxc container restart
|
||||
tags:
|
||||
- lxc_container_create-config
|
||||
|
||||
- name: Ensure bind mount host directories exists
|
||||
file:
|
||||
@ -192,8 +47,6 @@
|
||||
delegate_to: "{{ physical_host }}"
|
||||
notify:
|
||||
- Lxc container restart
|
||||
tags:
|
||||
- lxc_container_create-config
|
||||
|
||||
# NOTE(cloudnull): Should a container already be up and running with a defined container interface
|
||||
# the shell command will use the MAC address already set within the container as
|
||||
@ -212,8 +65,6 @@
|
||||
failed_when: false
|
||||
when:
|
||||
- lxc_container_fixed_mac | bool
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# NOTE(cloudnull): This task is being done to allow a container to have a static mac address.
|
||||
# before this task a container had a dynamic mac address which would
|
||||
@ -241,8 +92,6 @@
|
||||
- (ansible_local is not defined or
|
||||
'mac' not in ansible_local or
|
||||
inventory_hostname not in ansible_local['mac'])
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# NOTE(palendae): If we have saved MACs, write those out instead of generating new ones.
|
||||
# Parentheses on the mac in ansible_local check to make the YAML parser happy.
|
||||
@ -259,8 +108,6 @@
|
||||
- ansible_local is defined
|
||||
- ('mac' in ansible_local)
|
||||
- inventory_hostname in ansible_local['mac']
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
- name: Gather hardware addresses to be used as facts
|
||||
command: cat /var/lib/lxc/{{ inventory_hostname }}/{{ item.value.interface }}.hwaddr
|
||||
@ -270,8 +117,6 @@
|
||||
delegate_to: "{{ physical_host }}"
|
||||
when:
|
||||
- lxc_container_fixed_mac | bool
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# NOTE(cloudnull): To dynamically set the the mac address "facts" Ansible line format is being used
|
||||
- name: Set fixed hardware address fact
|
||||
@ -280,8 +125,6 @@
|
||||
- "{{ macs.results }}"
|
||||
when:
|
||||
- lxc_container_fixed_mac | bool
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# NOTE(palendae): If a unique identifier (like the hostname) is not provided as the marker, only one block will be written.
|
||||
# Each host will be written once, and whichever one came last will be the only one in the file.
|
||||
@ -294,8 +137,6 @@
|
||||
when:
|
||||
- lxc_container_fixed_mac | bool
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# NOTE(palendae): This is necessary to read any local facts in to the 'ansible_local' dict.
|
||||
- name: Read local facts in for use
|
||||
@ -316,16 +157,12 @@
|
||||
mode: "0644"
|
||||
with_dict: "{{ container_networks | default({}) }}"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
- name: Create start
|
||||
lxc_container:
|
||||
name: "{{ inventory_hostname }}"
|
||||
state: started
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-create
|
||||
|
||||
- name: Drop container network file (interfaces)
|
||||
template:
|
||||
@ -335,8 +172,6 @@
|
||||
group: "root"
|
||||
mode: "0644"
|
||||
with_dict: "{{ container_networks | default({}) }}"
|
||||
tags:
|
||||
- lxc_container_create-setup
|
||||
|
||||
- name: Drop container network file (routes)
|
||||
template:
|
||||
@ -351,8 +186,6 @@
|
||||
- item.value.static_routes is defined or
|
||||
(item.value.gateway is defined and ansible_pkg_mgr == "zypper")
|
||||
with_dict: "{{ container_networks | default({}) }}"
|
||||
tags:
|
||||
- lxc_container_create-setup
|
||||
|
||||
- name: Drop container setup script
|
||||
template:
|
||||
@ -361,16 +194,12 @@
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0755"
|
||||
tags:
|
||||
- lxc_container_create-setup
|
||||
|
||||
- name: Run container setup script
|
||||
command: /opt/container-setup.sh
|
||||
register: container_setup
|
||||
changed_when: false
|
||||
failed_when: container_setup.rc != 0
|
||||
tags:
|
||||
- lxc_container_create-setup
|
||||
|
||||
# NOTE(major): the lxc.network.veth.pair line must appear *immediately* after
|
||||
# the lxc.network.name congfiguration line or it will be ignored. That's why
|
||||
@ -382,8 +211,6 @@
|
||||
insertafter: "^lxc.network.name"
|
||||
backup: "true"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
- name: Container network includes
|
||||
lineinfile:
|
||||
@ -393,8 +220,6 @@
|
||||
with_dict: "{{ container_networks | default({}) }}"
|
||||
when: item.value.interface is defined
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
- name: Create wiring script
|
||||
copy:
|
||||
@ -404,8 +229,6 @@
|
||||
group: "root"
|
||||
mode: "0755"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
- name: Run container veth wiring script
|
||||
command: >
|
||||
@ -422,8 +245,6 @@
|
||||
failed_when: wiring_script.rc not in [3, 0]
|
||||
changed_when: wiring_script.rc == 3
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# Adds post-down and pre-start hooks
|
||||
- name: Drop veth cleanup script
|
||||
@ -434,8 +255,6 @@
|
||||
group: "root"
|
||||
mode: "0755"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# This is being defined due to an issue with dangling veth pairs.
|
||||
# TODO(someone) This should be removed once an upstream patch has
|
||||
@ -450,8 +269,6 @@
|
||||
- "lxc.hook.pre-start = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh"
|
||||
- "lxc.hook.post-stop = /var/lib/lxc/{{ inventory_hostname }}/veth-cleanup.sh"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
# Flush the handlers to ensure the container and networking is online.
|
||||
- meta: flush_handlers
|
||||
@ -462,8 +279,6 @@
|
||||
delay: "{{ lxc_container_wait_params.delay | default(omit) }}"
|
||||
sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}"
|
||||
timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}"
|
||||
tags:
|
||||
- lxc_container_create-networks
|
||||
|
||||
- name: Add global_environment_variables to environment file
|
||||
blockinfile:
|
||||
@ -473,8 +288,6 @@
|
||||
insertbefore: EOF
|
||||
block: "{{ lookup('template', 'environment.j2') }}"
|
||||
remote_user: root
|
||||
tags:
|
||||
- lxc_container_create-proxy
|
||||
|
||||
- name: Create localhost config
|
||||
lineinfile:
|
||||
@ -485,8 +298,6 @@
|
||||
group: "root"
|
||||
mode: "0644"
|
||||
remote_user: root
|
||||
tags:
|
||||
- lxc_container_create-hostname
|
||||
|
||||
- name: Create domain config
|
||||
lineinfile:
|
||||
@ -497,8 +308,6 @@
|
||||
group: "root"
|
||||
mode: "0644"
|
||||
remote_user: root
|
||||
tags:
|
||||
- lxc_container_create-hostname
|
||||
|
||||
- name: Create hostname
|
||||
copy:
|
||||
@ -508,15 +317,11 @@
|
||||
group: "root"
|
||||
mode: "0644"
|
||||
remote_user: root
|
||||
tags:
|
||||
- lxc_container_create-hostname
|
||||
|
||||
- name: Setup hostname
|
||||
command: hostname -F /etc/hostname
|
||||
changed_when: false
|
||||
remote_user: root
|
||||
tags:
|
||||
- lxc_container_create-hostname
|
||||
|
||||
- name: Ensure sysctl can be applied
|
||||
template:
|
||||
@ -526,8 +331,6 @@
|
||||
owner: "root"
|
||||
group: "root"
|
||||
remote_user: root
|
||||
tags:
|
||||
- lxc_container_create-sysctl
|
||||
|
||||
# NOTE(hwoarang) openSUSE randomly fails to start the service
|
||||
# with an error like the following one
|
||||
@ -547,15 +350,13 @@
|
||||
until: _sysctl_service_started|success
|
||||
retries: 5
|
||||
delay: 5
|
||||
tags:
|
||||
- lxc_container_create-sysctl
|
||||
|
||||
- name: Allow the usage of local facts
|
||||
file:
|
||||
path: /etc/ansible/facts.d/
|
||||
state: directory
|
||||
tags:
|
||||
- lxc_container_create-install
|
||||
- always
|
||||
|
||||
- name: Record the container variant deployed
|
||||
ini_file:
|
||||
@ -563,3 +364,5 @@
|
||||
section: lxc
|
||||
option: variant
|
||||
value: "{{ properties['lxc_container_variant'] | default(lxc_container_variant) }}"
|
||||
tags:
|
||||
- always
|
54
tasks/lxc_container_cow.yml
Normal file
54
tasks/lxc_container_cow.yml
Normal file
@ -0,0 +1,54 @@
|
||||
---
|
||||
# Copyright 2017, Rackspace US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Due to https://github.com/ansible/ansible-modules-extras/issues/2577 the
|
||||
# next two tasks do not use the lxc_container module.
|
||||
# TODO(odyssey4me): Revisit this once a fix has merged
|
||||
- name: Check if container exists
|
||||
command: "lxc-info -n {{ inventory_hostname }}"
|
||||
failed_when: false
|
||||
delegate_to: "{{ physical_host }}"
|
||||
register: lxc_container_info
|
||||
|
||||
# Due to https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1591510
|
||||
# the '-B' option is used, instead of the more understandable
|
||||
# '--backingstore'.
|
||||
# TODO(odyssey4me): Revisit this once a fix has merged
|
||||
# NOTE(hwoarang) lxc-copy is only available since lxc-2.0.0 so emulate
|
||||
# its behavior using the old lxc-clone command. This is only a problem
|
||||
# on openSUSE so it's safe to remove it when lxc-2.X becomes the default
|
||||
# option for openSUSE in the openstack-ansible-lxc_hosts role.
|
||||
- block:
|
||||
- name: Create container (cow)
|
||||
command: >
|
||||
lxc-copy --snapshot -B {{ lxc_container_backing_store }}
|
||||
--name {{ lxc_container_base_name }}
|
||||
--newname {{ inventory_hostname }}
|
||||
-L {{ properties.container_fs_size | default(lxc_container_fs_size) }}
|
||||
--logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
|
||||
--logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }}
|
||||
delegate_to: "{{ physical_host }}"
|
||||
rescue:
|
||||
# NOTE(hwoarang) lxc-clone does not support the common
|
||||
# --logfile/logpriority options so we just redirect everything to the log
|
||||
# which is probably the best we can do.
|
||||
- name: Create container (cow) (fallback)
|
||||
shell: >
|
||||
lxc-clone -s -B {{ lxc_container_backing_store }} -L {{ properties.container_fs_size | default(lxc_container_fs_size) }}
|
||||
{{ lxc_container_base_name }} {{ inventory_hostname }} &>>
|
||||
{{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
|
||||
delegate_to: "{{ physical_host }}"
|
||||
when:
|
||||
- lxc_container_info.rc != 0
|
58
tasks/lxc_container_create.yml
Normal file
58
tasks/lxc_container_create.yml
Normal file
@ -0,0 +1,58 @@
|
||||
---
|
||||
# Copyright 2014, Rackspace US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- name: Container service directories
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: "directory"
|
||||
with_items:
|
||||
- "/openstack/{{ inventory_hostname }}"
|
||||
- "/openstack/backup/{{ inventory_hostname }}"
|
||||
- "/openstack/log/{{ inventory_hostname }}"
|
||||
- "{{ lxc_container_directory }}/{{ inventory_hostname }}"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
|
||||
- name: LXC autodev setup
|
||||
template:
|
||||
src: "autodev.j2"
|
||||
dest: "/var/lib/lxc/{{ inventory_hostname }}/autodev"
|
||||
owner: "root"
|
||||
group: "root"
|
||||
mode: "0755"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
|
||||
# Run the lxc container creation process based on the backend store type
|
||||
- include: "lxc_container_create_{{ lxc_container_backing_store }}.yml"
|
||||
|
||||
- name: Check container state
|
||||
command: "lxc-info -n {{ inventory_hostname }} --state"
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
delegate_to: "{{ physical_host }}"
|
||||
register: _lxc_container_state
|
||||
|
||||
# Due to https://github.com/ansible/ansible-modules-extras/issues/2691
|
||||
# this uses the LXC CLI tools to ensure that we get logging.
|
||||
# TODO(odyssey4me): revisit this once the bug is fixed and released
|
||||
- name: Start the container if it is not already running
|
||||
command: >
|
||||
lxc-start
|
||||
--daemon
|
||||
--name {{ inventory_hostname }}
|
||||
--logfile {{ lxc_container_log_path }}/lxc-{{ inventory_hostname }}.log
|
||||
--logpriority {{ (debug | bool) | ternary('DEBUG', 'INFO') }}
|
||||
delegate_to: "{{ physical_host }}"
|
||||
when:
|
||||
- _lxc_container_state.stdout.find('STOPPED') != -1
|
18
tasks/lxc_container_create_btrfs.yml
Normal file
18
tasks/lxc_container_create_btrfs.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
# Copyright 2017, Rackspace US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- name: Not Implemented
|
||||
fail:
|
||||
msg: "BTRFS backed containers has not been implemented yet."
|
27
tasks/lxc_container_create_dir.yml
Normal file
27
tasks/lxc_container_create_dir.yml
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
# Copyright 2017, Rackspace US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- name: Create container (dir)
|
||||
lxc_container:
|
||||
name: "{{ inventory_hostname }}"
|
||||
container_log: true
|
||||
container_log_level: "{{ (debug | bool) | ternary('DEBUG', 'INFO') }}"
|
||||
config: "{{ lxc_container_config }}"
|
||||
template: "{{ lxc_container_template }}"
|
||||
state: started
|
||||
backing_store: "{{ lxc_container_backing_store }}"
|
||||
directory: "{{ lxc_container_rootfs_directory }}"
|
||||
template_options: "{{ lxc_container_download_template_options }}"
|
||||
delegate_to: "{{ physical_host }}"
|
36
tasks/lxc_container_create_lvm.yml
Normal file
36
tasks/lxc_container_create_lvm.yml
Normal file
@ -0,0 +1,36 @@
|
||||
---
|
||||
# Copyright 2017, Rackspace US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- name: Create container (lvm)
|
||||
lxc_container:
|
||||
name: "{{ inventory_hostname }}"
|
||||
container_log: true
|
||||
container_log_level: "{{ (debug | bool) | ternary('DEBUG', 'INFO') }}"
|
||||
config: "{{ lxc_container_config }}"
|
||||
template: "{{ lxc_container_template }}"
|
||||
state: started
|
||||
backing_store: "{{ lxc_container_backing_store }}"
|
||||
fs_size: "{{ properties.container_fs_size | default(lxc_container_fs_size) }}"
|
||||
fs_type: "{{ lxc_container_fs_type }}"
|
||||
vg_name: "{{ lxc_container_vg_name }}"
|
||||
template_options: "{{ lxc_container_download_template_options }}"
|
||||
delegate_to: "{{ physical_host }}"
|
||||
when:
|
||||
- lxc_container_backing_store == 'lvm'
|
||||
- lxc_container_backing_method != 'copy-on-write'
|
||||
|
||||
- include: lxc_container_cow.yml
|
||||
when:
|
||||
- lxc_container_backing_method == 'copy-on-write'
|
16
tasks/lxc_container_create_overlayfs.yml
Normal file
16
tasks/lxc_container_create_overlayfs.yml
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
# Copyright 2017, Rackspace US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- include: lxc_container_cow.yml
|
18
tasks/lxc_container_create_zfs.yml
Normal file
18
tasks/lxc_container_create_zfs.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
# Copyright 2017, Rackspace US, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- name: Not Implemented
|
||||
fail:
|
||||
msg: "ZFS backed containers has not been implemented yet."
|
@ -19,23 +19,25 @@
|
||||
state: directory
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc_container_create-install
|
||||
- always
|
||||
|
||||
- name: Ansible version and LXC backing store check
|
||||
fail:
|
||||
msg: "Using overlayfs is not supported when using Ansible version < 2"
|
||||
when:
|
||||
- lxc_container_backing_store is defined
|
||||
- lxc_container_backing_store == "overlayfs"
|
||||
- ansible_version.major < 2
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Kernel version and LXC backing store check
|
||||
debug:
|
||||
msg: "Using overlayfs is not recommended when using Kernel version < 3.18"
|
||||
when:
|
||||
- lxc_container_backing_store is defined
|
||||
- lxc_container_backing_store == "overlayfs"
|
||||
- hostvars[physical_host]['ansible_kernel'] | version_compare('3.18.0-0-generic', '<')
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Gather variables for each operating system
|
||||
include_vars: "{{ item }}"
|
||||
@ -48,16 +50,54 @@
|
||||
tags:
|
||||
- always
|
||||
|
||||
- include: container_destroy.yml
|
||||
when:
|
||||
- lxc_container_recreate | bool
|
||||
- name: Read custom facts from previous runs
|
||||
setup:
|
||||
filter: ansible_local
|
||||
delegate_to: "{{ physical_host }}"
|
||||
tags:
|
||||
- lxc-container-recreate
|
||||
- always
|
||||
|
||||
- include: container_create.yml
|
||||
# NOTE(cloudnull): Check for the LXC volume group when creating LVM backed
|
||||
# containers.
|
||||
- block:
|
||||
- name: Check for lxc volume group
|
||||
shell: "(which vgs > /dev/null && vgs | grep -o '{{ lxc_container_vg_name }}') || false"
|
||||
register: vg_result
|
||||
failed_when: false
|
||||
changed_when: vg_result.rc != 0
|
||||
delegate_to: "{{ physical_host }}"
|
||||
- name: LXC VG check
|
||||
fail:
|
||||
msg: >-
|
||||
The "lxc_container_backing_store" option was set to "lvm" but no LXC
|
||||
volume group was found on the physical host. Please check your settings
|
||||
and host setup.
|
||||
when:
|
||||
- vg_result.rc != 0
|
||||
when:
|
||||
- lxc_container_backing_store == 'lvm'
|
||||
tags:
|
||||
- always
|
||||
|
||||
- include: lxc_container_destroy.yml
|
||||
when:
|
||||
- physical_host is defined
|
||||
- inventory_hostname is defined
|
||||
- physical_host != inventory_hostname
|
||||
- lxc_container_recreate | bool
|
||||
|
||||
- include: lxc_container_create.yml
|
||||
when:
|
||||
- physical_host is defined
|
||||
- inventory_hostname is defined
|
||||
- physical_host != inventory_hostname
|
||||
tags:
|
||||
- lxc_container_create
|
||||
- lxc-create
|
||||
|
||||
- include: lxc_container_config.yml
|
||||
when:
|
||||
- physical_host is defined
|
||||
- inventory_hostname is defined
|
||||
- physical_host != inventory_hostname
|
||||
tags:
|
||||
- lxc-config
|
||||
|
Loading…
Reference in New Issue
Block a user