Workshop Exercise 2.5 - Initial Device Configuration Automation

Table of Contents

Objective

In this exercise, we’re going to create a playbook that does some simple initial configuration of our edge devices. This will get consumed later by a workflow so our devices are automatically configured correctly when they call home.

Our tasks in the playbook will be:

  1. Set the hostname to what the device identified itself as when calling home to Ansible Controller
  2. Set a resolver line in the /etc/hosts file

Step 1 - Writing Our Initial Device Configuration Playbook

Return to your code repository and create a new playbook in the playbooks directory called initial-device-config.yml. Enter the following contents:

---
- name: do initial device setup
  hosts: all
  tasks:
    - name: set the system hostname
      ansible.builtin.hostname:
        name: "{{ inventory_hostname }}"
    - name: insert line into /etc/hosts
      ansible.builtin.lineinfile:
        path: /etc/hosts
        line: '{{ ansible_default_ipv4.address }} {{ inventory_hostname }} {{ inventory_hostname }}.lcl'
        insertafter: EOF

Once complete, commit and push your new playbook up into Gitea.

Step 2 - Creating a Job Template

Note

Be sure to sync your project in Controller before attempting to create this job template.

In the Controller WebUI. under Resources > Templates, select Add > Add job template and enter the following information:

Parameter Value
Name Initial Device Configuration
Inventory Edge Systems
Project Device Edge Codebase
Execution Environment Device Edge Workshops Execution Environment
Playbook playbooks/initial-device-config.yml
Credentials
  • ✓ Device Credentials
Limit
  • ✓ Prompt on launch
  • Options
    • ✓ Privilege Escalation

    Remember to click Save.

    We’re not going to run this job right now, but instead leverage it in the next exercise.

    Solutions

    Initial Device Configuration Job Template


    Navigation

    Previous Exercise Next Exercise

    Click here to return to the Workshop Homepage