diff --git a/README.rst b/README.rst index 29b4ed2fa7911e1bf9ec9e904ee61f1b63a85b6b..4e3abea45732b0ce72e62f91c5d9466c06301b97 100644 --- a/README.rst +++ b/README.rst @@ -1,9 +1,7 @@ -Example -####### +lxc-host +######## -An (empty) example Ansible role complete with working tests out of the box. For -more information read the `blog post -<https://www.shore.co.il/blog/ansible-example-role/>`_. +Ansible role to configure an LXC host. Requirements ------------ @@ -58,3 +56,9 @@ Nimrod Adar, `contact me <nimrod@shore.co.il>`_ or visit my `website <https://www.shore.co.il/>`_. Patches are welcome via `git send-email <http://git-scm.com/book/en/v2/Git-Commands-Email>`_. The repository is located at: https://www.shore.co.il/git/. + +TODO +---- + +- Tests. +- Systemd-networkd DHCP server (fixed in which version of Debian/ Ubuntu). diff --git a/defaults/main.yml b/defaults/main.yml index 25ca86f325b131ae189e74bc108bcc2bc403501e..80ea3a680b8bd95882a4b90f2d9d57c7a289e571 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,2 @@ --- -# defaults file for ansible-role-example +# defaults file for lxc-host diff --git a/handlers/main.yml b/handlers/main.yml index 1d74a03c15eb4a405872128a9f81f91ecf354f2e..f0b980df1d66aedf51a4bf7b99757777efac6283 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,2 @@ --- -# handlers file for ansible-role-example +# handlers file for lxc-host diff --git a/meta/main.yml b/meta/main.yml index 2dea7f403f2774209b2935d8aecfe4e81d2379a8..9b5d94d5190737094de324e2519e11f9e793be7a 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,15 +1,22 @@ galaxy_info: author: Nimrod Adar - description: An example Ansible role + description: Ansible role to configure an LXC host company: Shore technologies license: MIT min_ansible_version: 2.0 platforms: - - name: OpenBSD + - name: Debian versions: - - 6.0 + - jessie + - stretch - name: Ubuntu versions: - xenial - galaxy_tags: [ ansible ] -dependencies: [] + galaxy_tags: [ lxc ] +dependencies: + - src: https://www.shore.co.il/git/ansible-role-networkd + scm: git + name: networkd + - src: https://www.shore.co.il/git/ansible-role-ufw + scm: git + name: ufw diff --git a/molecule.yml b/molecule.yml index 16a28c066171bd1ac65cf917161d8923d1751a91..36c8a252300cce244579091af996c71d35860316 100644 --- a/molecule.yml +++ b/molecule.yml @@ -11,12 +11,12 @@ vagrant: - name: virtualbox type: virtualbox platforms: - - name: openbsd - box: kaorimatz/openbsd-6.0-amd64 + - name: debian + box: debian/jessie64 - name: ubuntu box: ubuntu/xenial64 instances: - - name: ansible-role-example + - name: ansible-role-lxc-host options: append_platform_to_hostname: yes raw_config_args: diff --git a/tasks/main.yml b/tasks/main.yml index 5772d26c3fc71643ef5528765bde1543674a519f..444b0e07c25b0bbdbc179f60a445c8394959c6d4 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,8 +1,34 @@ --- -# tasks file for ansible-role-example +# tasks file for lxc-host - name: Assertions assert: that: - - ansible_os_family in ['OpenBSD', 'Debian'] - - ansible_distribution_release in ['6.0', 'xenial'] + - ansible_os_family == 'Debian' + - ansible_service_mgr == 'systemd' + - ansible_distribution_release in ['jessie', 'stretch', 'xenial'] + +- name: APT install + apt: + name: ['lxc', 'debootstrap', 'yum', 'dnsmasq', 'python-lxc'] + state: present + update_cache: yes + cache_valid_time: 3600 + +- name: Create bridge + with_items: + - lxcbr0.netdev + - lxcbr0.network + template: + src: '{{ item }}.j2' + dest: '/etc/systemd/network/{{ item }}' + owner: root + group: root + mode: 0o0644 + notify: + - Restart systemd-networkd + +- name: Allow IP forwarding in UFW + ufw: + direction: routed + policy: allow diff --git a/templates/lxcbr0.netdev.j2 b/templates/lxcbr0.netdev.j2 new file mode 100644 index 0000000000000000000000000000000000000000..86d2e918780e93ffae5f22b4be51d20bd676169c --- /dev/null +++ b/templates/lxcbr0.netdev.j2 @@ -0,0 +1,3 @@ +[NetDev] +Name=lxcbr0 +Kind=bridge diff --git a/templates/lxcbr0.network.j2 b/templates/lxcbr0.network.j2 new file mode 100644 index 0000000000000000000000000000000000000000..a5696489b5f939a345795abe158bd0816fdbc870 --- /dev/null +++ b/templates/lxcbr0.network.j2 @@ -0,0 +1,9 @@ +[Match] +Name=lxcbr0 + +[Network] +Address=192.168.123.0/24 +DHCPServer=yes +# Doesn't work due to bug #787480. +IPForward=yes +IPMasquerade=yes diff --git a/tests/playbook.yml b/tests/playbook.yml index 02cca1a33e13b3e2e2eb2fb91071f066de21fdf7..f4a0a9e933cee82120e9c289d939079a383e4584 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -1,12 +1,8 @@ --- -- hosts: ansible-role-example-openbsd - gather_facts: false - roles: [openbsd_bootstrap] - -- hosts: ansible-role-example-ubuntu +- hosts: ansible-role-lxc-host-ubuntu gather_facts: false roles: [debian_bootstrap] - hosts: all roles: - - role: ansible-role-example + - role: ansible-role-lxc-host diff --git a/vars/main.yml b/vars/main.yml index 241750308ae0dc5fd6fc0d21108c47746696d808..ec37e3e61f72f9190ea2239cbc0ea122d1b5762b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ --- -# vars file for ansible-role-example +# vars file for lxc-host