From 18ed41e5bdda5812cd5657f41033bd5a83e10f92 Mon Sep 17 00:00:00 2001 From: Arios Date: Wed, 30 Sep 2020 01:25:05 +0200 Subject: [PATCH 1/3] Migrate LXC roles primary host from PVE node to container By removing the primary PVE host dendency of these roles, more flexible inventory setups are possible, making provisioning of several containers in quick succession much easier. This change also required several role defaults to be changed, with some new variables added. It is thus not compatible with previous versions of these roles --- README.md | 2 +- roles/lxc_container/README.md | 54 +++++++++++++++++-- roles/lxc_container/defaults/main.yml | 10 ++-- roles/lxc_container/meta/main.yml | 21 -------- roles/lxc_container/tasks/bootstrap.yml | 6 ++- roles/lxc_container/tasks/main.yml | 3 +- roles/lxc_container/vars/main.yml | 2 - roles/lxc_container_to_ostemplate/README.md | 38 ++++++++++--- .../defaults/main.yml | 12 +++-- .../lxc_container_to_ostemplate/meta/main.yml | 21 -------- .../tasks/main.yml | 23 ++------ .../tasks/prepare.yml | 17 ++++++ .../lxc_container_to_ostemplate/vars/main.yml | 2 - 13 files changed, 125 insertions(+), 86 deletions(-) delete mode 100644 roles/lxc_container/meta/main.yml delete mode 100644 roles/lxc_container/vars/main.yml delete mode 100644 roles/lxc_container_to_ostemplate/meta/main.yml create mode 100644 roles/lxc_container_to_ostemplate/tasks/prepare.yml delete mode 100644 roles/lxc_container_to_ostemplate/vars/main.yml diff --git a/README.md b/README.md index 695bd6d..de64d9a 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,4 @@ GNU GPL3 or later # Author -Arios \ No newline at end of file +Arios diff --git a/roles/lxc_container/README.md b/roles/lxc_container/README.md index 47ed269..5f91874 100644 --- a/roles/lxc_container/README.md +++ b/roles/lxc_container/README.md @@ -18,9 +18,9 @@ Other distributions should work as well, as long as they: Requirements ------------ -A Proxmox VE host accessible via SSH and the PVE API. +A Proxmox VE host accessible via SSH and the PVE API (see `defaults/main.yml`) with `become` privileges. -The following python modules on the controller: +The following python modules are required on the controller: - proxmoxer - requests Install via pip: `pip3 install proxmoxer requests` @@ -38,10 +38,19 @@ None Example Playbook ---------------- +Generic example: + ``` -- hosts: pve_host +- hosts: all roles: - lxc_container: + # This role will connect to this PVE host for various tasks related to container setup + # Make sure that the pve_host (here: pve1.example.com) is present in your inventory + # and that ansible can connect via SSH (+ become) and via API + pve_host: pve1.example.com + pve_api_user: root@pam + pve_api_password: some-password + # Parameters for the container that you want to create lxccreate_hostname: a-hostname lxccreate_ostemplate: local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz lxccreate_netif: @@ -49,6 +58,45 @@ Example Playbook lxccreate_password: a-root-password ``` +Creating a batch of containers based on an inventory is also possible using a customized inventory. An example layout is show below: + +Inventory: +``` +all: + children: + containers: + hosts: + 192.168.1.123: + # Variables unique to every container + lxccreate_hostname: ct-a + lxccreate_netif: + net0: name=eth0,bridge=vmbr0,ip=192.168.1.123/24,gw=192.168.1.1,firewall=0 + ... + 192.168.1.124: + ... + # Common variables shared between containers + lxccreate_ostemplate: local:vztmpl/ubuntu-20.04-standard_20.04-1_amd64.tar.gz + lxccreate_cores: 4 + # PVE connection variables + pve_api_user: root@pam + pve_api_password: some-secret-password + pve_host: pve1.example.com + ... + hosts: + pve1.example.com: + # Parameters for the PVE API and SSH host. + ansible_user: root +``` + +``` + # This will create a set of containers, with each container being a member of the `containers` group +- hosts: containers + serial: 1 # Needed to prevent race conditions + roles: + - name: lxc_container +``` + + License ------- diff --git a/roles/lxc_container/defaults/main.yml b/roles/lxc_container/defaults/main.yml index 6a005a7..f772577 100644 --- a/roles/lxc_container/defaults/main.yml +++ b/roles/lxc_container/defaults/main.yml @@ -1,7 +1,9 @@ --- -# Login information for the PVE API. We use the API -# to create and start LXC containers -pve_api_host: '{{ ansible_fqdn }}' +# This role needs API and SSH access to a PVE node with become privileges +# in order to create a container. Please set pve_host to the corresponding +# inventory hostname +pve_host: pve.example.com +pve_api_host: '{{ pve_host }}' pve_api_user: root@pam pve_api_password: mypassword @@ -39,4 +41,4 @@ lxccreate_timeout: 120 # Set this to no if you want to skip bootstrapping the container # (ssh server, python) -lxccreate_bootstrap: yes \ No newline at end of file +lxccreate_bootstrap: yes diff --git a/roles/lxc_container/meta/main.yml b/roles/lxc_container/meta/main.yml deleted file mode 100644 index c386af5..0000000 --- a/roles/lxc_container/meta/main.yml +++ /dev/null @@ -1,21 +0,0 @@ -galaxy_info: - author: Arios - description: Create and bootstrap an LXC container on a Proxmox node - company: "" - - license: GPL-3.0-or-later - - min_ansible_version: 2.9 - - platforms: - - name: Debian - versions: - - all - - galaxy_tags: - - proxmox - - lxc - - container - - bootstrap - -dependencies: [] diff --git a/roles/lxc_container/tasks/bootstrap.yml b/roles/lxc_container/tasks/bootstrap.yml index 3648245..66f579c 100644 --- a/roles/lxc_container/tasks/bootstrap.yml +++ b/roles/lxc_container/tasks/bootstrap.yml @@ -3,6 +3,7 @@ register: pve_cluster_vms changed_when: no check_mode: no + become: yes - name: Get guest VMID set_fact: pve_current_vmid: '{{ (pve_cluster_vms.stdout | from_json | selectattr("name", "match", lxccreate_hostname) | map(attribute="vmid") | list).0 }}' @@ -10,7 +11,10 @@ copy: src: bootstrap-ct.sh dest: /tmp/bootstrap-ct.sh + become: yes - name: Copy bootstrap script to container # noqa 301 command: 'pct push {{ pve_current_vmid }} /tmp/bootstrap-ct.sh /tmp/bootstrap-ct.sh --perms 777' + become: yes - name: Bootstrap container # noqa 301 - command: 'pct exec {{ pve_current_vmid }} /tmp/bootstrap-ct.sh' \ No newline at end of file + command: 'pct exec {{ pve_current_vmid }} /tmp/bootstrap-ct.sh' + become: yes diff --git a/roles/lxc_container/tasks/main.yml b/roles/lxc_container/tasks/main.yml index 3411d5d..2d0a16c 100644 --- a/roles/lxc_container/tasks/main.yml +++ b/roles/lxc_container/tasks/main.yml @@ -1,6 +1,7 @@ --- - include: ostemplate.yml + delegate_to: '{{ pve_host }}' - include: provision.yml - include: bootstrap.yml + delegate_to: '{{ pve_host }}' when: lxccreate_bootstrap and pve_lxccreate_task.changed - become: yes \ No newline at end of file diff --git a/roles/lxc_container/vars/main.yml b/roles/lxc_container/vars/main.yml deleted file mode 100644 index 08648ea..0000000 --- a/roles/lxc_container/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for lxc_create \ No newline at end of file diff --git a/roles/lxc_container_to_ostemplate/README.md b/roles/lxc_container_to_ostemplate/README.md index db26919..0abe493 100644 --- a/roles/lxc_container_to_ostemplate/README.md +++ b/roles/lxc_container_to_ostemplate/README.md @@ -10,7 +10,7 @@ This role performs the following actions: Requirements ------------ -A Proxmox VE host accessible via SSH and the PVE API. +A Proxmox VE host accessible via SSH and the PVE API that is running the target container (see `defaults/main.yml`) with `become` privileges. Role Variables -------------- @@ -25,15 +25,39 @@ None Example Playbook ---------------- -- hosts: pve_node +``` +- hosts: all roles: - role: lxc_container_to_ostemplate - pve_lxcostemplate_hostname: ubuntu-18-04 - pve_lxcostemplate_image: custom-ubuntu-18-04 - pve_lxcostemplate_storage: local - + pve_host: mypvehost.example.com + pve_ssh_user: root + lxcostemplate_hostname: ubuntu-18-04 + lxcostemplate_image: custom-ubuntu-18-04 + lxcostemplate_storage: local +``` + +Creating a batch of containers based on an inventory is also possible using a customized inventory. An example layout is show below: + +Inventory: +``` +all: + children: + containers: + hosts: + 192.168.1.123: + # Variables unique to every container + lxcostemplate_hostname: ct-a + lxcostemplate_image: custom-ct-a + ... + 192.168.1.124: + ... + # Common variables shared between containers + lxcostemplate_storage: local + pve_host: mypvehost.example.com + ... +``` License ------- -GPL 3 or later \ No newline at end of file +GPL 3 or later diff --git a/roles/lxc_container_to_ostemplate/defaults/main.yml b/roles/lxc_container_to_ostemplate/defaults/main.yml index f1473c1..3e9c1d3 100644 --- a/roles/lxc_container_to_ostemplate/defaults/main.yml +++ b/roles/lxc_container_to_ostemplate/defaults/main.yml @@ -1,5 +1,11 @@ --- -# defaults file for lxc_container_to_ostemplate +# SSH access to a PVE host is required in order to execute this role. You should +# define the host in your inventory and set pve_host accordingly +# +# Note that the target container *must* be running on this host. +# The host must also have access to the storage defined in lxcostemplate_storage +pve_host: pve.example.com +pve_ssh_user: root # Set either the hostname or the vmid of the container to convert into a template. # If both are set, the vmid will take precedence @@ -7,11 +13,9 @@ lxcostemplate_vmid: lxcostemplate_hostname: # Select the type of vzdump backup to perform. Options are stop, suspend and snapshot lxcostemplate_vzdump_mode: snapshot - # Name of the ostemplate image to generate. .tar.gz will be appended automatically lxcostemplate_image: custom-ubuntu_18.04 # Name of the storage volume under which the ostemplate will be saved lxcostemplate_storage: local - # Set to yes if you want to overwrite an already existing image -lxcostemplate_overwrite: no \ No newline at end of file +lxcostemplate_overwrite: no diff --git a/roles/lxc_container_to_ostemplate/meta/main.yml b/roles/lxc_container_to_ostemplate/meta/main.yml deleted file mode 100644 index 14e4722..0000000 --- a/roles/lxc_container_to_ostemplate/meta/main.yml +++ /dev/null @@ -1,21 +0,0 @@ -galaxy_info: - author: Arios - description: Generate an ostemplate image from a LXC container - company: - - license: GPL-3.0-or-later - - min_ansible_version: 2.9 - - platforms: - - name: Debian - versions: - - all - - galaxy_tags: - - proxmox - - lxc - - container - - template - -dependencies: [] diff --git a/roles/lxc_container_to_ostemplate/tasks/main.yml b/roles/lxc_container_to_ostemplate/tasks/main.yml index de1c8bb..d22d5c8 100644 --- a/roles/lxc_container_to_ostemplate/tasks/main.yml +++ b/roles/lxc_container_to_ostemplate/tasks/main.yml @@ -9,24 +9,9 @@ lxcostemplate_storage_path: /mnt/pve/template/cache when: lxcostemplate_storage != "local" -- name: Look for existing image - stat: - path: '{{ lxcostemplate_storage_path }}/{{ lxcostemplate_image }}.tar.gz' - register: lxcostemplate_existing_image - when: not lxcostemplate_overwrite - -- block: - - name: Get cluster VMs - command: pvesh get /cluster/resources -type vm --output-format json - register: cluster_vms - changed_when: no - check_mode: no - become: yes - - name: Get guest VMID - set_fact: - lxcostemplate_vmid: '{{ (cluster_vms.stdout | from_json | selectattr("name", "match", lxcostemplate_hostname) | map(attribute="vmid") | list).0 }}' - when: not lxcostemplate_vmid - +- include: prepare.yml + delegate_to: '{{ pve_host }}' - include: generate.yml + delegate_to: '{{ pve_host }}' when: (not lxcostemplate_overwrite and not lxcostemplate_existing_image.stat.exists) or - lxcostemplate_overwrite \ No newline at end of file + lxcostemplate_overwrite diff --git a/roles/lxc_container_to_ostemplate/tasks/prepare.yml b/roles/lxc_container_to_ostemplate/tasks/prepare.yml new file mode 100644 index 0000000..233d46c --- /dev/null +++ b/roles/lxc_container_to_ostemplate/tasks/prepare.yml @@ -0,0 +1,17 @@ +- name: Look for existing image + stat: + path: '{{ lxcostemplate_storage_path }}/{{ lxcostemplate_image }}.tar.gz' + register: lxcostemplate_existing_image + when: not lxcostemplate_overwrite + +- block: + - name: Get cluster VMs + command: pvesh get /cluster/resources -type vm --output-format json + register: cluster_vms + changed_when: no + check_mode: no + become: yes + - name: Get guest VMID + set_fact: + lxcostemplate_vmid: '{{ (cluster_vms.stdout | from_json | selectattr("name", "match", lxcostemplate_hostname) | map(attribute="vmid") | list).0 }}' + when: not lxcostemplate_vmid diff --git a/roles/lxc_container_to_ostemplate/vars/main.yml b/roles/lxc_container_to_ostemplate/vars/main.yml deleted file mode 100644 index bd3f594..0000000 --- a/roles/lxc_container_to_ostemplate/vars/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -# vars file for lxc_container_to_ostemplate \ No newline at end of file From 3f726c798c8f687592b9c1c42e0ce2339a079741 Mon Sep 17 00:00:00 2001 From: Arios Date: Wed, 30 Sep 2020 01:33:55 +0200 Subject: [PATCH 2/3] Updated tests for new lxc roles --- molecule/lxc/README.md | 5 +-- molecule/lxc/converge.yml | 13 ++++--- .../lxc/inventory/group_vars/containers.yml | 26 +++++++++++++ .../group_vars/custom_containers.yml | 26 +++++++++++++ .../inventory/host_vars/192.168.111.100.yml | 6 +++ .../host_vars}/192.168.111.200.yml | 0 .../host_vars}/192.168.111.201.yml | 0 .../host_vars}/192.168.111.202.yml | 0 .../host_vars}/192.168.111.203.yml | 0 .../host_vars}/192.168.111.204.yml | 0 .../host_vars}/192.168.111.205.yml | 0 .../host_vars}/192.168.111.206.yml | 0 .../host_vars}/192.168.111.207.yml | 0 .../host_vars}/192.168.111.220.yml | 0 .../host_vars}/192.168.111.221.yml | 0 .../host_vars}/192.168.111.222.yml | 0 .../host_vars}/192.168.111.223.yml | 0 .../host_vars}/192.168.111.224.yml | 0 .../host_vars}/192.168.111.225.yml | 0 .../host_vars}/192.168.111.226.yml | 0 .../host_vars}/192.168.111.227.yml | 0 molecule/lxc/inventory/host_vars/pve.yml | 1 + molecule/lxc/inventory/hosts.yml | 27 ++++++++++++++ molecule/lxc/molecule.yml | 37 ++----------------- molecule/lxc/prepare.yml | 4 +- .../lxc/tasks/converge_lxc_containers.yml | 14 ------- molecule/lxc/tasks/verify_lxc_containers.yml | 10 ----- molecule/lxc/verify.yml | 15 ++++++-- 28 files changed, 113 insertions(+), 71 deletions(-) create mode 100644 molecule/lxc/inventory/group_vars/containers.yml create mode 100644 molecule/lxc/inventory/group_vars/custom_containers.yml create mode 100644 molecule/lxc/inventory/host_vars/192.168.111.100.yml rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.200.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.201.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.202.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.203.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.204.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.205.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.206.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.207.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.220.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.221.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.222.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.223.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.224.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.225.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.226.yml (100%) rename molecule/lxc/{vars => inventory/host_vars}/192.168.111.227.yml (100%) create mode 100644 molecule/lxc/inventory/host_vars/pve.yml create mode 100644 molecule/lxc/inventory/hosts.yml delete mode 100644 molecule/lxc/tasks/converge_lxc_containers.yml delete mode 100644 molecule/lxc/tasks/verify_lxc_containers.yml diff --git a/molecule/lxc/README.md b/molecule/lxc/README.md index 112a4cb..c7c54d3 100644 --- a/molecule/lxc/README.md +++ b/molecule/lxc/README.md @@ -84,7 +84,6 @@ This setup allows us to test multiple nodes and guests, while preventing compati We provision multiple containers to test the bootstrap process on various distributions. If you need to add a new distro/container, follow these steps: -1. Add the container the inventory in `molecule.yml`. Use the next free IP address in the host-only network (counting from 200 for containers) -2. Add the custom container based on the template in `molecule.yml`. Use the next free IP address in the host-only network (counting form 2020) -2. Set the containers hostvars in `vars/${CONTAINER_IP}.yml`: +1. Add the container and the custom template-generated version to the inventory in `inventory/hosts.yml`. Use the next free IP address in the host-only network (counting from 200 for containers and 220 for the custom ones) +2. Set the containers hostvars in `inventory/host_vars/${CONTAINER_IP}.yml`: - Make sure that both network interfaces are configured properly, using the IP address from step 1 (see the other containers for reference) diff --git a/molecule/lxc/converge.yml b/molecule/lxc/converge.yml index 3a85064..b55b03f 100644 --- a/molecule/lxc/converge.yml +++ b/molecule/lxc/converge.yml @@ -1,7 +1,10 @@ --- - name: Converge - hosts: pve_nodes - tasks: - - name: Create containers and ostemplates - include: tasks/converge_lxc_containers.yml - loop: '{{ groups["containers"] }}' \ No newline at end of file + hosts: containers + gather_facts: no + serial: 1 # Prevent race conditions + roles: + - name: ../../roles/lxc_container + - name: ../../roles/lxc_container_to_ostemplate + lxcostemplate_hostname: '{{ lxccreate_hostname }}' + lxcostemplate_image: '{{ lxcostemplate_custom_prefix }}{{ lxccreate_ostemplate.split("/").1.split(".tar").0 }}' diff --git a/molecule/lxc/inventory/group_vars/containers.yml b/molecule/lxc/inventory/group_vars/containers.yml new file mode 100644 index 0000000..8c985cf --- /dev/null +++ b/molecule/lxc/inventory/group_vars/containers.yml @@ -0,0 +1,26 @@ +pve_host: 192.168.111.100 +pve_api_user: root@pam +# The API password is equivalent to the root password we set on the pve host +pve_api_password: '{{ hostvars["pve"]["pve_root_password"] }}' + +# Prefix to differentiate between the provided and our generated template images +lxcostemplate_custom_prefix: custom- + +lxccreate_node: pve # Must be the same as the host that the role is executed on +lxccreate_cores: 2 +lxccreate_cpus: 1 +lxccreate_cpuunits: 1024 +lxccreate_memory: 1024 +lxccreate_swap: 0 +lxccreate_disk: "10" +lxccreate_storage: local-lvm +lxccreate_mounts: {} +lxccreate_onboot: no +lxccreate_ostemplate_download: yes +lxccreate_nameserver: "8.8.8.8,8.8.4.4" +lxccreate_searchdomain: "localdomain" +lxccreate_password: a-secret-password +lxccreate_pubkey: '{{ lookup("file", "~/.ssh/id_rsa.pub") }}' +lxccreate_unprivileged: yes +lxccreate_timeout: 120 +lxccreate_bootstrap: yes diff --git a/molecule/lxc/inventory/group_vars/custom_containers.yml b/molecule/lxc/inventory/group_vars/custom_containers.yml new file mode 100644 index 0000000..8c985cf --- /dev/null +++ b/molecule/lxc/inventory/group_vars/custom_containers.yml @@ -0,0 +1,26 @@ +pve_host: 192.168.111.100 +pve_api_user: root@pam +# The API password is equivalent to the root password we set on the pve host +pve_api_password: '{{ hostvars["pve"]["pve_root_password"] }}' + +# Prefix to differentiate between the provided and our generated template images +lxcostemplate_custom_prefix: custom- + +lxccreate_node: pve # Must be the same as the host that the role is executed on +lxccreate_cores: 2 +lxccreate_cpus: 1 +lxccreate_cpuunits: 1024 +lxccreate_memory: 1024 +lxccreate_swap: 0 +lxccreate_disk: "10" +lxccreate_storage: local-lvm +lxccreate_mounts: {} +lxccreate_onboot: no +lxccreate_ostemplate_download: yes +lxccreate_nameserver: "8.8.8.8,8.8.4.4" +lxccreate_searchdomain: "localdomain" +lxccreate_password: a-secret-password +lxccreate_pubkey: '{{ lookup("file", "~/.ssh/id_rsa.pub") }}' +lxccreate_unprivileged: yes +lxccreate_timeout: 120 +lxccreate_bootstrap: yes diff --git a/molecule/lxc/inventory/host_vars/192.168.111.100.yml b/molecule/lxc/inventory/host_vars/192.168.111.100.yml new file mode 100644 index 0000000..8e594da --- /dev/null +++ b/molecule/lxc/inventory/host_vars/192.168.111.100.yml @@ -0,0 +1,6 @@ +# We contact the PVE host via this IP address, but molecule/vagrant sees it as "pve", +# as explained in the README. We can simply reuse the hostvars from each other though, so it's +# no big deal + +ansible_user: root +ansible_ssh_pass: '{{ hostvars["pve"]["pve_root_password"] }}' diff --git a/molecule/lxc/vars/192.168.111.200.yml b/molecule/lxc/inventory/host_vars/192.168.111.200.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.200.yml rename to molecule/lxc/inventory/host_vars/192.168.111.200.yml diff --git a/molecule/lxc/vars/192.168.111.201.yml b/molecule/lxc/inventory/host_vars/192.168.111.201.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.201.yml rename to molecule/lxc/inventory/host_vars/192.168.111.201.yml diff --git a/molecule/lxc/vars/192.168.111.202.yml b/molecule/lxc/inventory/host_vars/192.168.111.202.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.202.yml rename to molecule/lxc/inventory/host_vars/192.168.111.202.yml diff --git a/molecule/lxc/vars/192.168.111.203.yml b/molecule/lxc/inventory/host_vars/192.168.111.203.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.203.yml rename to molecule/lxc/inventory/host_vars/192.168.111.203.yml diff --git a/molecule/lxc/vars/192.168.111.204.yml b/molecule/lxc/inventory/host_vars/192.168.111.204.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.204.yml rename to molecule/lxc/inventory/host_vars/192.168.111.204.yml diff --git a/molecule/lxc/vars/192.168.111.205.yml b/molecule/lxc/inventory/host_vars/192.168.111.205.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.205.yml rename to molecule/lxc/inventory/host_vars/192.168.111.205.yml diff --git a/molecule/lxc/vars/192.168.111.206.yml b/molecule/lxc/inventory/host_vars/192.168.111.206.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.206.yml rename to molecule/lxc/inventory/host_vars/192.168.111.206.yml diff --git a/molecule/lxc/vars/192.168.111.207.yml b/molecule/lxc/inventory/host_vars/192.168.111.207.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.207.yml rename to molecule/lxc/inventory/host_vars/192.168.111.207.yml diff --git a/molecule/lxc/vars/192.168.111.220.yml b/molecule/lxc/inventory/host_vars/192.168.111.220.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.220.yml rename to molecule/lxc/inventory/host_vars/192.168.111.220.yml diff --git a/molecule/lxc/vars/192.168.111.221.yml b/molecule/lxc/inventory/host_vars/192.168.111.221.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.221.yml rename to molecule/lxc/inventory/host_vars/192.168.111.221.yml diff --git a/molecule/lxc/vars/192.168.111.222.yml b/molecule/lxc/inventory/host_vars/192.168.111.222.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.222.yml rename to molecule/lxc/inventory/host_vars/192.168.111.222.yml diff --git a/molecule/lxc/vars/192.168.111.223.yml b/molecule/lxc/inventory/host_vars/192.168.111.223.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.223.yml rename to molecule/lxc/inventory/host_vars/192.168.111.223.yml diff --git a/molecule/lxc/vars/192.168.111.224.yml b/molecule/lxc/inventory/host_vars/192.168.111.224.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.224.yml rename to molecule/lxc/inventory/host_vars/192.168.111.224.yml diff --git a/molecule/lxc/vars/192.168.111.225.yml b/molecule/lxc/inventory/host_vars/192.168.111.225.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.225.yml rename to molecule/lxc/inventory/host_vars/192.168.111.225.yml diff --git a/molecule/lxc/vars/192.168.111.226.yml b/molecule/lxc/inventory/host_vars/192.168.111.226.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.226.yml rename to molecule/lxc/inventory/host_vars/192.168.111.226.yml diff --git a/molecule/lxc/vars/192.168.111.227.yml b/molecule/lxc/inventory/host_vars/192.168.111.227.yml similarity index 100% rename from molecule/lxc/vars/192.168.111.227.yml rename to molecule/lxc/inventory/host_vars/192.168.111.227.yml diff --git a/molecule/lxc/inventory/host_vars/pve.yml b/molecule/lxc/inventory/host_vars/pve.yml new file mode 100644 index 0000000..cd80687 --- /dev/null +++ b/molecule/lxc/inventory/host_vars/pve.yml @@ -0,0 +1 @@ +pve_root_password: molecule_test diff --git a/molecule/lxc/inventory/hosts.yml b/molecule/lxc/inventory/hosts.yml new file mode 100644 index 0000000..3c191d9 --- /dev/null +++ b/molecule/lxc/inventory/hosts.yml @@ -0,0 +1,27 @@ +all: + children: + # Containers created from the PVE-supplied images + containers: + hosts: + 192.168.111.200: + 192.168.111.201: + 192.168.111.202: + 192.168.111.203: + 192.168.111.204: + 192.168.111.205: + 192.168.111.206: + 192.168.111.207: + # Containers created from our generated images using the containers above + custom_containers: + hosts: + 192.168.111.220: + 192.168.111.221: + 192.168.111.222: + 192.168.111.223: + 192.168.111.224: + 192.168.111.225: + 192.168.111.226: + 192.168.111.227: + hosts: + # PVE node API + SSH access, used by the roles + 192.168.111.100: diff --git a/molecule/lxc/molecule.yml b/molecule/lxc/molecule.yml index 39cfc24..11c23a4 100644 --- a/molecule/lxc/molecule.yml +++ b/molecule/lxc/molecule.yml @@ -39,39 +39,10 @@ provisioner: defaults: host_key_checking: no inventory: - hosts: - all: - children: - # Containers created from the PVE-supplied images - containers: - hosts: - 192.168.111.200: - 192.168.111.201: - 192.168.111.202: - 192.168.111.203: - 192.168.111.204: - 192.168.111.205: - 192.168.111.206: - 192.168.111.207: - # Containers created from our generated images using the containers above - custom_containers: - hosts: - 192.168.111.220: - 192.168.111.221: - 192.168.111.222: - 192.168.111.223: - 192.168.111.224: - 192.168.111.225: - 192.168.111.226: - 192.168.111.227: - group_vars: - all: - # Prefix to differentiate between the provided and our generated template images - lxcostemplate_custom_prefix: custom- - pve_nodes: - # Set the API address to the NET2 IP - pve_api_host: '{{ ansible_vmbr0.ipv4.address }}' - pve_api_password: molecule_test + links: + hosts: inventory/hosts.yml + group_vars: inventory/group_vars + host_vars: inventory/host_vars verifier: name: ansible diff --git a/molecule/lxc/prepare.yml b/molecule/lxc/prepare.yml index 8bbbc0b..c97de1d 100644 --- a/molecule/lxc/prepare.yml +++ b/molecule/lxc/prepare.yml @@ -3,7 +3,7 @@ - name: Set root user password user: name: root - password: '{{ pve_api_password | password_hash("sha512") }}' + password: '{{ pve_root_password | password_hash("sha512") }}' become: yes - name: Network config is installed template: @@ -14,4 +14,4 @@ service: name: networking state: restarted - become: yes \ No newline at end of file + become: yes diff --git a/molecule/lxc/tasks/converge_lxc_containers.yml b/molecule/lxc/tasks/converge_lxc_containers.yml deleted file mode 100644 index 29508c3..0000000 --- a/molecule/lxc/tasks/converge_lxc_containers.yml +++ /dev/null @@ -1,14 +0,0 @@ -- name: Load container vars - include_vars: - file: '{{ item }}.yml' - -- name: Create container - include_role: - name: ../../roles/lxc_container - -- name: Generate container ostemplate - include_role: - name: ../../roles/lxc_container_to_ostemplate - vars: - lxcostemplate_hostname: '{{ lxccreate_hostname }}' - lxcostemplate_image: '{{ lxcostemplate_custom_prefix }}{{ lxccreate_ostemplate.split("/").1.split(".tar").0 }}' diff --git a/molecule/lxc/tasks/verify_lxc_containers.yml b/molecule/lxc/tasks/verify_lxc_containers.yml deleted file mode 100644 index e9a18fc..0000000 --- a/molecule/lxc/tasks/verify_lxc_containers.yml +++ /dev/null @@ -1,10 +0,0 @@ -- name: Load container vars - include_vars: - file: '{{ item }}.yml' - -- name: Create new container - include_role: - name: ../../roles/lxc_container - vars: - lxccreate_bootstrap: no - lxccreate_ostemplate_download: no diff --git a/molecule/lxc/verify.yml b/molecule/lxc/verify.yml index ad99f5c..95758fb 100644 --- a/molecule/lxc/verify.yml +++ b/molecule/lxc/verify.yml @@ -8,10 +8,17 @@ setup: - name: Create containers from generated ostemplates - hosts: pve_nodes - tasks: - - include: tasks/verify_lxc_containers.yml - loop: '{{ groups["custom_containers"] }}' + hosts: custom_containers + gather_facts: no + serial: 1 + roles: + - name: ../../roles/lxc_container + lxccreate_bootstrap: no + lxccreate_ostemplate_download: no + post_tasks: + - name: Wait for containers to start + pause: + seconds: 30 - name: Verify new containers hosts: custom_containers From acf22abd0b5fc9203a3e62102704e0343d03a909 Mon Sep 17 00:00:00 2001 From: Arios Date: Wed, 30 Sep 2020 01:44:14 +0200 Subject: [PATCH 3/3] Update version number --- galaxy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/galaxy.yml b/galaxy.yml index d9c2dcf..4b6e586 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -9,7 +9,7 @@ namespace: ariosthephoenix name: proxmox # The version of the collection. Must be compatible with semantic versioning -version: 1.0.0 +version: 2.0.0 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md