Workshop Exercise 2.3 - Templating Out Our Kickstart

Table of Contents

Objective

In this exercise, we’re going to write a simple playbook to template out our kickstart file, create a job template for it, run the job template, then review the generated kickstart file. Once complete, we should have a functional kickstart ready to use with our edge devices.

Step 1 - Writing a Playbook to Template out our Kickstart

Return to the code repo via the method that you were editing files (VSCode, VIM, etc) previously, and create a new playbook in the playbooks/ directory of your repo called template-kickstart.yml. We’ll only need one task for this playbook which will be used to render the kickstart file to a directory served by the web server.

Populate the template-kickstart.yml file with the following content:

---

- name: template out kickstart file
  hosts:
    - all
  become: true
  tasks:
    - name: push templated kickstart file
      ansible.builtin.template:
        src: templates/student{{ student_number }}.ks.j2
        dest: "/var/www/html/student{{ student_number }}-kickstart.ks"
        owner: apache
        group: apache
        mode: '0755'

A few notes about this playbook:

Once your playbook is constructed, push it up into your git repo.

Step 2 - Creating a Job Template for our Playbook

Note

Be sure to sync your project in Controller before attempting to create this job template. To sync the project, navigate to Resources > Project and click on the sync icon for the only project available

Now that we have a playbook and template, we can build a job template to push our our kickstart file.

On the Resources > Templates page, select Add > Add job template and enter the following information:

Parameter Value
Name Template Out Kickstart
Inventory Edge Utilities
Project Device Edge Codebase
Execution Environment Device Edge Workshops Execution Environment
Playbook playbooks/template-kickstart.yml
Credentials
  • ✓ Ansible Controller API Authentication Info
  • ✓ Machine -> Edge Manager SSH Credentials
  • ✓ Kickstart User
  • ✓ OSTree Info
  • ✓ Wireless Network Info (If applicable)
Limit edge_manager
Options
  • ✓ Privilege Escalation

Remember to click Save.

Note

If you’re not planning to kickstart over wifi, then the Wireless Network Info credential is not needed.

Step 3 - Running the Job Template

Now that the job template has been created, click on the Launch button to start a Job. Monitor the output for any errors or issues.

As a reminder, the output of jobs can be reviewed on the Jobs tab.

Step 4 - Reviewing the Kickstart File

Once the job has completed, the kickstart file can be viewed immediately via connecting to the web server. Open a web browser and navigate to http://(edge-manager-from-your-student-page)/student$(your-student-number)-kickstart.ks

Ideally, the variables and conditional blocks will have templated properly, and the kickstart will be filled out with all the correct information. Review the contents of the kickstart to confirm the values you’re expecting are present.

Remember: a portion of the playbook was surrounded by the raw key, meaning Ansible didn’t attempt to resolve/replace the variables and rendered the content as it was declared. This is by design, as our playbook has some of its own variables.

Solutions

Template Kickstart job template:

Template Kickstart Job Template

Template Kickstart select credentials:

Template Kickstart Select Credentials


Navigation

Previous Exercise Next Exercise

Click here to return to the Workshop Homepage