Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Role improved #1

Merged
merged 10 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
remote_tmp = /tmp/.ansible-${USER}/tmp
local_tmp = $HOME/.ansible/tmp
pipelining=True

17 changes: 8 additions & 9 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
---
lxd_apt_stable_repo: yes
lxd_packages:
- lxd
- zfsutils-linux
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep zfsutils-linux.


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'
Expand Down Expand Up @@ -48,4 +47,4 @@ lxd_config:
# Add DNS servers to dhcp
lxd_prepend_dns: []

lxd_containters: []
lxd_containers: []
10 changes: 6 additions & 4 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,15 +16,15 @@
- 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 }}'
notify: restart networking

- 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

Expand Down
1 change: 1 addition & 0 deletions tasks/containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}'
Expand Down
9 changes: 9 additions & 0 deletions tasks/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Install dependencies
apt:
name: '{{ item }}'
update_cache: true
with_items:
- software-properties-common
- snapd
24 changes: 17 additions & 7 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
---
- 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 }}'
with_items:
- lxd
- lxd-client

- name: Install LXD with snap
shell: snap install {{ item }}
with_items:
- lxd --channel=3.0
- lxd
changed_when: false

- 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
9 changes: 6 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions tests/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 2 additions & 1 deletion tests/inventory
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
localhost ansible_connection=local
# localhost ansible_connection=local
lxc ansible_host=10.180.70.93
22 changes: 16 additions & 6 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
---

- hosts: localhost
become: True
- hosts: all
become: true
roles:
- role: plumelo.lxd
lxd_packages: ['lxd']
lxd_users: ['travis']
lxd_users: ['ubuntu']
lxd_dns_ipv4: '10.229.31.1'
lxd_prepend_dns: ['{{ lxd_dns_ipv4 }}']
lxd_default_bridge_ipv4_address: '{{ lxd_dns_ipv4 }}/24'
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