Create ISO image from Files and Folders - Ansible module iso_create
How to automate the creation of a "test.iso" ISO9660 file containing an "helloworld.txt" file using Ansible Playbook and iso_create module.


How to Create ISO image from Files and Folders with Ansible?
I’m going to show you a live demo with some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot
Create ISO images from the Files and Folders
community.general.iso_create
- Generate ISO files with specified files or folders
Let’s talk about the Ansible module iso_create
.
The full name is community.general.iso_create
, which means that is part of the collection of modules “community.general” maintained by the Ansible Community.
This module requires the extra pycdlib
Python library. You can easily install the pycdlib
Python library using PIP, the Python Package Installer.
The purpose of the module is to generate ISO files with specified files or folders.
Parameters
dest_iso
path - ISO file absolute pathsrc_files
list - absolute paths of source files or folderinterchange_level
integer - ISO9660 standards (1–4)joliet
integer - Joliet extension (1–3)rock_ridge
string - Rock Ridge extension (1.09, 1.10, 1.12)udf
boolean - no/yes UDF support 2.60
Let me summarize the main parameters of the module iso_create
.
The required parameters are “dest_iso” and “src_files”.
The “dest_iso” parameter contains the generated ISO file absolute path according to the ISO9660 standard.
The “src_files” parameter contains the list of absolute paths of source files or folders.
You probably would like to set to four the “interchange_level” parameter because it allows you to specify which of the fourth ISO9660 standards to support, default to “1”.
Level 1 is the most restrictive standard and Level 4 is the most permissive one.
With all ISO9660 levels from 1 to 3, all file names are restricted to uppercase letters, numbers, and underscores (_). File names are limited to 31 characters, directory nesting is limited to 8 levels, and path names are limited to 255 characters.
Level 1 allows a maximum of 8 characters for names and 3 characters in the extension.
Joliet is a popular ISO9660 extension in the Windows-like environment that you could enable setting to three the “joliet” parameter to allow the support of filenames up to 103 characters in length (according to the mkisofs documentation).
Rock Ridge is another popular ISO9660 extension in the Unix-like operating systems to enable up to 255 bytes long file names and soft/hard links. You can enable the “1.12” specification setting accordingly the “rock_ridge” parameter.
Another popular extension is the Universal Disk Format (UDF) which allows files to be created, deleted, and changed on a disc just as a general-purpose filesystem. You can enable the UDF specification 2.60 setting the “udf” boolean.
Links
The Best Resources For Ansible
Video Course
Printed Book
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
demo
Let’s jump into a real-life Ansible Playbook to Create ISO images from Files and Folders.
I’m going to show you how to create an example.iso
image with a file “helloworld.txt” inside the user’s devopshome directory.
code
- create_iso.yml
---
- name: iso_create module demo
hosts: all
tasks:
- name: Create an ISO file
community.general.iso_create:
src_files:
- /home/devops/helloworld.txt
dest_iso: /home/devops/test.iso
interchange_level: 4
joliet: 3
execution
ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory file_management/create_iso.yml
PLAY [iso_create module demo] *********************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [Create an ISO file] *************************************************************************
changed: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible-pilot $
not-idempotent
ansible-pilot $ ansible-playbook -i virtualmachines/demo/inventory file_management/create_iso.yml
PLAY [iso_create module demo] *********************************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [Create an ISO file] *************************************************************************
changed: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible-pilot $
before execution
$ ssh [email protected]
[[email protected] ~]$ ls
helloworld.txt
[[email protected] ~]$
after execution
ansible-pilot $ ssh [email protected]
[[email protected] ~]$ ls
helloworld.txt test.iso
[[email protected] ~]$ file test.iso
test.iso: ISO 9660 CD-ROM filesystem data ''
[[email protected] ~]$ cat helloworld.txt
example
[[email protected] ~]$ sudo mount -t iso9660 test.iso /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
[[email protected] ~]$ ls -al /mnt/helloworld.txt
-r-xr-xr-x. 1 root root 8 Aug 18 09:24 /mnt/virtualbox/helloworld.txt
[[email protected] ~]$ cat /mnt/helloworld.txt
example
[[email protected] ~]$
Recap
Now you know how to create an ISO image from Files and Folders. Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate