stafwag.cloud_localds
Ansible Role: cloud_localds
This Ansible role is used to create cloud-init configuration disk images. It acts as a wrapper around the cloud-localds
command.
Requirements
You need to have cloud-localds
.
Supported GNU/Linux Distributions
This role should work on most GNU/Linux distributions. However, cloud-localds
is needed. It is available on Centos/RedHat 7, but not on RedHat 8. You will need to install it manually if you are using Centos/RedHat 8.
Supported distributions include:
- Archlinux
- Debian
- Centos 7
- RedHat 7
- Ubuntu
Role tasks, tags, variables, and templates
Tasks
install
All tasks related to installation are included in the
install
playbook. This helps you install the necessary packages and start/enable the required services usingtasks_from
in theinclude_role
,import_role
, and other Ansible modules.See the example below.
Tags
install
This tag is used to install the required packages.
Playbook-related variables
- cloud_localds: "namespace"
- dest: The destination image
- hostname: The hostname
- dir: Optional; defaults to
/var/lib/libvirt/images
. This is the destination directory if dest is not defined. - config: The user-data configuration
- network_config: The network configuration
- config_template: Use an Ansible template for the user-data configuration.
- network_config_template: Use an Ansible template for the network configuration.
- owner: uid; defaults to 0. The file owner of the destination image.
- group: gid; defaults to 0. The file group owner of the destination image.
- mode: mode; defaults to '0400'. The permissions of the destination image.
- overwrite: boolean; defaults to false. Set to overwrite the destination ISO if it already exists.
The role creates an ISO disk image with the cloud-init configuration.
When cloud_localds.dest is defined, these files are created:
- {{ cloud_localds.dest }}_config.yml: The cloud-init user-data
- {{ cloud_localds.dest }}_net_config.yml: The cloud-init network config (if network_config is defined)
- {{ cloud_localds.dest }}: The ISO image with the cloud-init configuration.
If cloud_localds.dest is not defined, you must define cloud_localds.hostname. In this case, the following files will be created:
- {{ cloud_localds.dir }}/{{ cloud_localds.hostname }}_config.yml: The cloud-init user-data
- {{ cloud_localds.dir }}/{{ cloud_localds.hostname }}_net_config.yml: The cloud-init network config (if network_config is defined)
- {{ cloud_localds.dir }}/{{ cloud_localds.hostname }}_cloud-init.iso: The ISO image with the cloud-init configuration.
Example Playbooks
Install the cloud-localds package with include_role
---
- name: Install libvirt & co
gather_facts: true
hosts: all
become: true
tasks:
- name: Install the requirements
include_role:
name: "{{ item }}"
tasks_from:
install
with_items:
- stafwag.libvirt
- stafwag.qemu_img
- stafwag.cloud_localds
tags:
- install
Create a cloud-init ISO with the destination defined
- name: Create config.iso
gather_facts: no
become: true
hosts: localhost
roles:
- role: stafwag.cloud_localds
vars:
cloud_localds:
dest: /var/lib/libvirt/images/tstdebian_cloudinit.iso
config: "{{ lookup('template','files/mytstdebian.j2') }}"
network_config: "{{ lookup('template','files/mytstdebian.j2') }}"
Create a cloud-init ISO with the hostname defined
---
- name: Create config.iso
gather_facts: no
become: true
hosts: localhost
roles:
- role: stafwag.cloud_localds
vars:
cloud_localds:
hostname: tstdebian
config: "{{ lookup('template','files/mytstdebian.j2') }}"
network_config: "{{ lookup('template','files/mytstdebian.j2') }}"
Use Ansible templates
---
- name: Create config.iso
gather_facts: true
become: true
hosts: localhost
roles:
- role: stafwag.cloud_localds
vars:
cloud_localds:
hostname: tstdebian
config_template: "files/debian/debian.j2"
network_config_template: "files/debian/debian.j2"
License
MIT/BSD
Author Information
Created by Staf Wagemakers. Email: staf@wagemakers.be, Website: http://www.wagemakers.be.
An ansible role to create cloud-init config disk images.
ansible-galaxy install stafwag.cloud_localds