Skip to content

Commit

Permalink
Merge pull request #2 from mila-iqia/doc/move_readme
Browse files Browse the repository at this point in the history
doc: move readme of role to roles/container
  • Loading branch information
btravouillon authored Feb 25, 2022
2 parents 761973b + f664c53 commit a459684
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 133 deletions.
133 changes: 1 addition & 132 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,135 +18,4 @@ The below requirements are needed on the host that executes this collection:

## Roles

### container

To manage containers, use the role `mila.proxmox.container`. This role makes use
of the Ansible modules `community.general.proxmox_template` and
`community.general.proxmox`.

The containers are created from a list defined in `proxmox_container`. Each item
in the list defines one container.

Example for a container:

proxmox_container:
- hostname: 'container1'
node: 'pve-1'
ostemplate: 'local:vztmpl/debian-11-standard_11.0-1_amd64.tar.gz'
disk: 'local:2'
cores: 2
nameserver: '10.10.0.1'
netif: '{"net0":"name=eth0,gw=10.10.0.254,hwaddr=42:4d:69:6c:61:00,ip=dhcp,bridge=vmbr0"}'
unprivileged: True
features:
- nesting=1 # For systemd, otherwise takes a lot of time to open ssh session

The role will parse `ostemplate` to ensure the required template is available on
all hosts.

Most of the parameters supported by the module `community.general.proxmox` can
be defined in the list. The following parameters are not supported yet, but
this might change in future development: `api_password`, `ip_address`,
`mounts`, `password`, `pool`, `purge`, `searchdomain` and `storage`. Note that
`proxmox_default_behavior` is enforced to `no_defaults`.

To authenticate to the REST API of your Proxmox VE cluster, you first need to
create an [API token][pve_api_tokens], then you must define the 4 **mandatory**
variables below:

- `proxmox_api_host`: the hostname or IP address of the Proxmox VE API server
- `proxmox_api_user`: the user name to authenticate (e.g. `ansible@pam`)
- `proxmox_api_token_id`: the token name (e.g. `prod`)
- `proxmox_api_token_secret`: the token secret provided by ProxmoxVE

[pve_api_tokens]: https://pve.proxmox.com/pve-docs/chapter-pveum.html#pveum_tokens

It is also possible to define the user, token id or token secret on a per
container basis for use cases where the management of a container requires
different access privileges.

proxmox_container:
- hostname: 'container2'
node: 'pve-1'
api_user: 'root@pam'
api_token_secret: 'MySecretShouldBeInAVault ;)'
features:
- keyctl=1 # This feature needs root access in ProxmoxVE
[...]

In the example above, `item.api_user` and `item.api_token_secret` will
respectively replace the values of `proxmox_api_user` and
`proxmox_api_token_secret`.

The example below creates two containers that will serve as DHCP servers. The
configuration of the DHCP service is not managed by this role. The variable
`proxmox_container_dhcp` is defined as a play variable. It is then passed to
`proxmox_container` as a role parameter. It is advised to define it in your
Ansible inventory.

- name: Instanciate DHCP servers in PVE
hosts: localhost
vars:
proxmox_api_token_secret: "{{ lookup('env','PROXMOX_API_TOKEN') }}"
proxmox_container_dhcp:
- hostname: 'dhcp1'
node: 'pve-1'
ostemplate: 'local:vztmpl/debian-11-standard_11.0-1_amd64.tar.gz'
disk: 'local:2'
cores: 2
nameserver: '10.10.0.1'
netif: '{"net0":"name=eth0,gw=10.10.0.254,ip=10.10.0.2/24,bridge=vmbr0"}'
unprivileged: True
features:
- nesting=1 # For systemd, otherwise takes a lot of time to open ssh session
- hostname: 'dhcp2'
node: 'pve-2'
ostemplate: 'local:vztmpl/debian-11-standard_11.0-1_amd64.tar.gz'
disk: 'local:2'
cores: 2
nameserver: '10.10.0.1'
netif: '{"net0":"name=eth0,gw=10.10.0.254,ip=10.10.0.3/24,bridge=vmbr0"}'
unprivileged: True
features:
- nesting=1 # For systemd, otherwise takes a lot of time to open ssh session
roles:
- name: Download proxmox appliance container template
role: mila.proxmox.container
vars:
proxmox_container: "{{ proxmox_container_dhcp }}"


Once a container exists, some parameters cannot be changed with the
`community.general.proxmox` module. To circumvent this limitation, it is
possible to destroy the containers and recreate these. For this, include the
role `mila.proxmox.container` in the pre_tasks of your playbook, with
`tasks_from: destroy`.

- name: Instanciate containers
hosts: localhost
pre_tasks:
- name: Ensure existing containers are removed
block:
- name: Remove SSH public host keys
ansible.builtin.known_hosts:
name: "{{ item }}"
state: absent
loop:
- 10.10.0.2
- 10.10.0.3
- name: Cleanup containers
ansible.builtin.include_role:
name: mila.proxmox.container
tasks_from: destroy
vars:
proxmox_container: "{{ proxmox_container_list }}"
when: proxmox_container_destroy_first is defined and proxmox_container_destroy_first
roles:
- name: Instanciate containers in Proxmox VE cluster
role: mila.proxmox.container
vars:
proxmox_container: "{{ proxmox_container_list }}"

In the example above, ansible-playbook must run with `-e
proxmox_container_destroy_first=True` for the destruction of the containers to
be effective.
* [container](roles/container/README.md)
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace: mila
name: proxmox

# The version of the collection. Must be compatible with semantic versioning
version: 0.1.0
version: 0.1.1

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
132 changes: 132 additions & 0 deletions roles/container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# mila.proxmox.container

To manage containers, use the role `mila.proxmox.container`. This role makes use
of the Ansible modules `community.general.proxmox_template` and
`community.general.proxmox`.

The containers are created from a list defined in `proxmox_container`. Each item
in the list defines one container.

Example for a container:

proxmox_container:
- hostname: 'container1'
node: 'pve-1'
ostemplate: 'local:vztmpl/debian-11-standard_11.0-1_amd64.tar.gz'
disk: 'local:2'
cores: 2
nameserver: '10.10.0.1'
netif: '{"net0":"name=eth0,gw=10.10.0.254,hwaddr=42:4d:69:6c:61:00,ip=dhcp,bridge=vmbr0"}'
unprivileged: True
features:
- nesting=1 # For systemd, otherwise takes a lot of time to open ssh session

The role will parse `ostemplate` to ensure the required template is available on
all hosts.

Most of the parameters supported by the module `community.general.proxmox` can
be defined in the list. The following parameters are not supported yet, but
this might change in future development: `api_password`, `ip_address`,
`mounts`, `password`, `pool`, `purge`, `searchdomain` and `storage`. Note that
`proxmox_default_behavior` is enforced to `no_defaults`.

To authenticate to the REST API of your Proxmox VE cluster, you first need to
create an [API token][pve_api_tokens], then you must define the 4 **mandatory**
variables below:

- `proxmox_api_host`: the hostname or IP address of the Proxmox VE API server
- `proxmox_api_user`: the user name to authenticate (e.g. `ansible@pam`)
- `proxmox_api_token_id`: the token name (e.g. `prod`)
- `proxmox_api_token_secret`: the token secret provided by ProxmoxVE

[pve_api_tokens]: https://pve.proxmox.com/pve-docs/chapter-pveum.html#pveum_tokens

It is also possible to define the user, token id or token secret on a per
container basis for use cases where the management of a container requires
different access privileges.

proxmox_container:
- hostname: 'container2'
node: 'pve-1'
api_user: 'root@pam'
api_token_secret: 'MySecretShouldBeInAVault ;)'
features:
- keyctl=1 # This feature needs root access in ProxmoxVE
[...]

In the example above, `item.api_user` and `item.api_token_secret` will
respectively replace the values of `proxmox_api_user` and
`proxmox_api_token_secret`.

The example below creates two containers that will serve as DHCP servers. The
configuration of the DHCP service is not managed by this role. The variable
`proxmox_container_dhcp` is defined as a play variable. It is then passed to
`proxmox_container` as a role parameter. It is advised to define it in your
Ansible inventory.

- name: Instanciate DHCP servers in PVE
hosts: localhost
vars:
proxmox_api_token_secret: "{{ lookup('env','PROXMOX_API_TOKEN') }}"
proxmox_container_dhcp:
- hostname: 'dhcp1'
node: 'pve-1'
ostemplate: 'local:vztmpl/debian-11-standard_11.0-1_amd64.tar.gz'
disk: 'local:2'
cores: 2
nameserver: '10.10.0.1'
netif: '{"net0":"name=eth0,gw=10.10.0.254,ip=10.10.0.2/24,bridge=vmbr0"}'
unprivileged: True
features:
- nesting=1 # For systemd, otherwise takes a lot of time to open ssh session
- hostname: 'dhcp2'
node: 'pve-2'
ostemplate: 'local:vztmpl/debian-11-standard_11.0-1_amd64.tar.gz'
disk: 'local:2'
cores: 2
nameserver: '10.10.0.1'
netif: '{"net0":"name=eth0,gw=10.10.0.254,ip=10.10.0.3/24,bridge=vmbr0"}'
unprivileged: True
features:
- nesting=1 # For systemd, otherwise takes a lot of time to open ssh session
roles:
- name: Download proxmox appliance container template
role: mila.proxmox.container
vars:
proxmox_container: "{{ proxmox_container_dhcp }}"


Once a container exists, some parameters cannot be changed with the
`community.general.proxmox` module. To circumvent this limitation, it is
possible to destroy the containers and recreate these. For this, include the
role `mila.proxmox.container` in the pre_tasks of your playbook, with
`tasks_from: destroy`.

- name: Instanciate containers
hosts: localhost
pre_tasks:
- name: Ensure existing containers are removed
block:
- name: Remove SSH public host keys
ansible.builtin.known_hosts:
name: "{{ item }}"
state: absent
loop:
- 10.10.0.2
- 10.10.0.3
- name: Cleanup containers
ansible.builtin.include_role:
name: mila.proxmox.container
tasks_from: destroy
vars:
proxmox_container: "{{ proxmox_container_list }}"
when: proxmox_container_destroy_first is defined and proxmox_container_destroy_first
roles:
- name: Instanciate containers in Proxmox VE cluster
role: mila.proxmox.container
vars:
proxmox_container: "{{ proxmox_container_list }}"

In the example above, ansible-playbook must run with `-e
proxmox_container_destroy_first=True` for the destruction of the containers to
be effective.

0 comments on commit a459684

Please sign in to comment.