diff --git a/.travis.yml b/.travis.yml index d5c24d0..97d9973 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,13 @@ --- +dist: xenial sudo: required language: python python: - "2.7" script: - sudo pip install ansible + - sudo snap install lxd - sudo ansible-playbook -i tests/inventory -vvvv tests/test.yml - > sudo ansible-playbook -i tests/inventory -vvvv tests/test.yml diff --git a/ansible.cfg b/ansible.cfg index 209cdbc..4ccd718 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -2,4 +2,3 @@ remote_tmp = /tmp/.ansible-${USER}/tmp local_tmp = $HOME/.ansible/tmp pipelining=True - diff --git a/defaults/main.yml b/defaults/main.yml index e1d74a3..d64d457 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,22 +1,23 @@ --- -lxd_apt_stable_repo: yes -lxd_packages: - - lxd - - zfsutils-linux + +lxd_install: true + +lxd_default_url: unix:/var/snap/lxd/common/lxd/unix.socket + lxd_users: [] -lxd_init: yes +lxd_init: true -#lxc init: default pool +# lxc init: default pool lxd_default_pool_size: 39GB lxd_default_pool_driver: zfs -lxd_default_pool_zfs_acl: 'off' #posixacl, noacl, off +lxd_default_pool_zfs_acl: 'off' # posixacl, noacl, off lxd_default_pool_config: size: '{{ lxd_default_pool_size }}' source: /var/lib/lxd/disks/default.img zfs.pool_name: default -#lxd init: default bridge +# lxd init: default bridge lxd_default_bridge_ipv4_address: 'auto' lxd_default_bridge_config: ipv4.nat: 'true' @@ -48,4 +49,4 @@ lxd_config: # Add DNS servers to dhcp lxd_prepend_dns: [] -lxd_containters: [] +lxd_containers: [] diff --git a/handlers/main.yml b/handlers/main.yml index de4832e..c5ef156 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -3,3 +3,9 @@ service: name: networking state: restarted + +- name: restart lxd + systemd: + name: lxd + state: restarted + daemon-reload: true diff --git a/tasks/configure.yml b/tasks/configure.yml index ad4bc96..6fc68ec 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,8 +1,10 @@ --- - name: Deploy LXD preseed - template: src="{{ lxd_config_preseed }}" dest="/tmp/lxd.preseed" - when: lxd_init|default(False) + template: + src: "{{ lxd_config_preseed }}" + dest: "/tmp/lxd.preseed" + when: lxd_init|default(false) register: lxd_preseed_status - name: Configure LXD @@ -14,7 +16,7 @@ - name: Add LXD DNS to dhcp blockinfile: dest: /etc/dhcp/dhclient.conf - backup: yes + backup: true block: 'prepend domain-name-servers {{ item }};' marker: '#{mark} LXD DNS' with_items: '{{ lxd_prepend_dns }}' @@ -22,7 +24,7 @@ - name: Get acl status for default pool shell: zfs get acltype default | grep default | awk '{print $3}' - when: lxd_default_pool_driver == 'zfs' and lxd_init|default(False) + when: lxd_default_pool_driver == 'zfs' and lxd_init|default(false) register: lxd_zfs_acl_status changed_when: lxd_zfs_acl_status.stdout != lxd_default_pool_zfs_acl diff --git a/tasks/containers.yml b/tasks/containers.yml index 21f7f3f..96de2c2 100644 --- a/tasks/containers.yml +++ b/tasks/containers.yml @@ -15,6 +15,7 @@ config: '{{ item.config | default(omit) }}' wait_for_ipv4_addresses: '{{ item.wait_for_ipv4_addresses | default(omit)}}' devices: '{{ item.devices | default(omit) }}' + url: '{{ item.url| default(lxd_default_url) }}' become: '{{ item.become | default(omit) }}' become_method: '{{ item.become_method | default(omit) }}' become_flags: '{{ item.become_flags | default(omit) }}' diff --git a/tasks/dependencies.yml b/tasks/dependencies.yml new file mode 100644 index 0000000..3e9e332 --- /dev/null +++ b/tasks/dependencies.yml @@ -0,0 +1,10 @@ +--- + +- name: Install dependencies + apt: + name: '{{ item }}' + update_cache: true + with_items: + - software-properties-common + - snapd + - zfsutils-linux diff --git a/tasks/install.yml b/tasks/install.yml index 264b104..e84e4d9 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,13 +1,29 @@ --- -- name: Ensure APT LXD repository (stable) - apt_repository: repo='ppa:ubuntu-lxc/lxd-stable' update_cache='yes' - when: lxd_apt_stable_repo -- name: Install LXD - package: name={{ item }} state=present - with_items: '{{ lxd_packages }}' +- name: Ensure there is no lxd installed from repo + apt: + name: '{{ item }}' + state: absent + with_items: + - lxd + - lxd-client + +- name: Create lxd group + group: + name: lxd + state: present - name: Add users to lxd group - user: name={{ item }} groups=lxd append=yes + user: + name: '{{ item }}' + groups: lxd + append: true with_items: '{{ lxd_users }}' register: lxd_group_users_status + +- name: Install LXD with snap + shell: snap install {{ item }} + with_items: + - lxd --channel=3.0 + when: lxd_install == "true" + changed_when: false diff --git a/tasks/main.yml b/tasks/main.yml index 6fb31ee..03a5ce0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,10 +1,13 @@ --- -- include: install.yml +- import_tasks: dependencies.yml tags: [lxd, lxd-install] -- include: configure.yml +- import_tasks: install.yml + tags: [lxd, lxd-install] + +- import_tasks: configure.yml tags: [lxd, lxd-configure] -- include: containers.yml +- import_tasks: containers.yml tags: [lxd, lxd-containers] diff --git a/tests/Vagrantfile b/tests/Vagrantfile index e59f276..dd34f22 100644 --- a/tests/Vagrantfile +++ b/tests/Vagrantfile @@ -11,6 +11,7 @@ Vagrant.configure("2") do |config| config.vm.provision 'ansible' do |ansible| ansible.playbook = 'test.yml' + ansible.extra_vars = { ansible_python_interpreter: '/usr/bin/python3' } end end diff --git a/tests/config.yml b/tests/config.yml new file mode 100644 index 0000000..d95e650 --- /dev/null +++ b/tests/config.yml @@ -0,0 +1,7 @@ +--- + + security.nesting=true + security.privileged=true + raw.lxc: |- + lxc.apparmor.profile=unconfined + lxc.cgroup.devices.allow=a diff --git a/tests/inventory b/tests/inventory index 2302eda..d361b68 100644 --- a/tests/inventory +++ b/tests/inventory @@ -1 +1,2 @@ localhost ansible_connection=local +# lxc-test ansible_connection=lxd ansible_python_interpreter='/usr/bin/python3' diff --git a/tests/test.yml b/tests/test.yml index 9feb16c..e263512 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,10 +1,10 @@ --- -- hosts: localhost - become: True +- hosts: all + become: true roles: - role: plumelo.lxd - lxd_packages: ['lxd'] + lxd_install: false lxd_users: ['travis'] lxd_dns_ipv4: '10.229.31.1' lxd_prepend_dns: ['{{ lxd_dns_ipv4 }}'] @@ -12,17 +12,29 @@ lxd_default_pool_driver: dir lxd_default_pool_config: {} cloud_config: + package_upgrade: true manage_etc_hosts: true + hostname: xenial packages: - python - acl - sudo + lxd_user_data: "#cloud-config\n{{ cloud_config|to_yaml(indent=2) }}" lxd_containers: - name: xenial state: started become_user: travis alias: 'x' config: - user.user-data: "#cloud-config\n{{ cloud_config|combine({'hostname': 'xenial'})|to_yaml(indent=2) }}" + security.nesting: 'true' + security.privileged: 'true' + user.user-data: "{{lxd_user_data}}" devices: {} timeout: 600 + +# lxc_config: +# security.nesting=true +# security.privileged=true +# raw.lxc: |- +# lxc.apparmor.profile=unconfined +# lxc.cgroup.devices.allow=a