Workshop Exercise 2.4 - Using the infra.osbuild Collection in a Playbook

Table of Contents

Objective

In this exercise, we are going to construct a playbook to read in our image definition and call the appropriate role in the infra.osbuild collection.

This exercise will cover:

Step 1 - Including a Vars File in a Playbook

First, let’s start a new file in our code repo: playbooks/compose-image.yml. This will be a playbook that we’ll use to build our images. This playbook will look very similar to other Ansible playbooks:

---

- name: compose an image via Image Builder
  hosts:
    - all
  vars_files:
    - files/image-definition.yml

Ansible has a keyword at the playbook to automatically read in variable files that we’ll use to read in the vars file we previously created, which is what the last two lines of the playbook above do. Also note: we’re using the relative path to our image definition vars file, but also could use an absolute path if we wanted.

Later on, we’ll load it into a job template in Controller, but let’s continue to build our playbook.

Step 2 - Converting Our Image Definition to Code

All we need to do now is have the playbook run the appropriate role from the infra.osbuild collection. Currently, the collection has two roles: one for setting up Image Builder called setup_server, and another for composing images called builder.

Because we’re calling a role within a collection, we’ll need the role’s fully qualified name in our playbook:

  roles:
    - infra.osbuild.builder

This rounds our playbook. Be sure to save/commit this playbook to your code repo.

Solutions

A fully composed playbook at playbooks/compose-image.yml:

---

- name: compose an image via Image Builder
  hosts:
    - all
  vars_files:
    - files/image-definition.yml
  roles:
    - infra.osbuild.builder    

Navigation

Previous Exercise Next Exercise

Click here to return to the Workshop Homepage