Create a requirements.yml file in a project to download and install an Ansible Role, and then use automation controller to automatically get that role and run a playbook that uses it.
Outcomes
Create a requirements file to specify role dependencies for a playbook in a Git repository.
Create a project in automation controller that points to the Git repository.
Launch a job template that automatically retrieves the playbook role dependencies from the requirements file.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command also creates a project directory with the files needed for the exercise.
[student@workstation ~]$ lab start simplify-external
Instructions
Verify that the Message of the Day (MOTD) banner is not configured on the iosxe1.lab.example.com managed node.
Connect to the iosxe1.lab.example.com managed node as the student user:
[student@workstation ~]$ ssh student@iosxe1.lab.example.com
iosxe1.lab.example.com#Return to the workstation machine:
iosxe1.lab.example.com#exit
Connection to iosxe1.lab.example.com closed by remote host.
Connection to iosxe1.lab.example.com closed.From the automation controller web UI, create a project that points to the simplify-external Git project.
Use the information in the following table to create the project:
| Field | Value |
|---|---|
Cisco IOS MOTD
| |
Default
| |
Git
| |
git@git.lab.example.com:student/simplify-external
| |
Git Projects
| |
Delete
| |
Allow Branch Override
|
Navigate to https://controller.lab.example.com and log in as admin using redhat as the password.
Navigate to → and then click .
Create the project with settings from the preceding table and then click .
Automation controller immediately attempts to synchronize the project. The field updates to indicate that the project synchronization succeeded.
If synchronization fails, ensure that the project specifies the correct source control URL and credentials and then attempt the project synchronization again.
Create a job template to run the ios_motd.yml playbook from the Cisco IOS MOTD automation controller project.
Launch the job template and review the job output.
Use the information in the following table to create the job template:
| Field | Value |
|---|---|
Cisco IOS MOTD banner
| |
Configure a MOTD banner on Cisco IOS managed nodes
| |
Common
| |
Cisco IOS MOTD
| |
ios_motd.yml
| |
Cisco IOS XE Auth
|
Navigate to → and then click → .
Create the job template with settings from the preceding table and then click .
Click to run the job template.
Navigate to → and look for a numbered job with Cisco IOS MOTD banner in the name.
The job displays a status of .
Click the name of the Cisco IOS MOTD banner job to review the job output.
The ios_motd.yml playbook fails in the Configure the MOTD banner task:
...output omitted... TASK [Configure the MOTD banner] *************************************************ERROR! the role 'banner' was not foundin /runner/project/roles:/runner/requirements_roles:/home/runner/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/runner/project The error appears to be in '/runner/project/ios_motd.yml': line 12, column 15, but may be elsewhere in the file depending on the exact syntax problem.The offending line appears to be:ansible.builtin.include_role:name: banner^ here...output omitted...
The task fails because the playbook includes the banner role, but the project does not indicate where to find that role.
Clone the git@git.lab.example.com:student/simplify-external Git repository into the /home/student/git-repos directory.
Create a branch named exercise and check out that branch.
On the workstation machine, change to the /home/student/git-repos directory and then use the git clone command to clone the git@git.lab.example.com:student/simplify-external Git repository:
[student@workstation ~]$cd ~/git-repos/[student@workstation git-repos]$git clone \git@git.lab.example.com:student/simplify-externalCloning into 'simplify-external'... remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (3/3), done.
Change to the simplify-external directory, and then create a branch named exercise and check it out:
[student@workstation git-repos]$cd simplify-external[student@workstation simplify-external]$git checkout -b exerciseSwitched to a new branch 'exercise'
Open the /home/student/git-repos/simplify-external directory in VS Code.
Examine the ios_motd.yml playbook.
Notice that the playbook uses the banner role.
For this task to succeed, the banner role must be installed.
Open VS Code and click → .
Navigate to → and click .
If prompted, select , and then click .
Examine the ios_motd.yml playbook.
The playbook uses the ansible.builtin.include_role module to include the banner role.
---
- name: Add a MOTD banner on Cisco IOS managed nodes
hosts: ios
gather_facts: false
tasks:
- name: Configure the MOTD banner
vars:
banner_text: Managed by Ansible
banner_type: motd
ansible.builtin.include_role:
name: bannerNotice that the playbook is the only file in the Git repository and the playbook does not specify where to find the banner role.
Create a role requirements file in your project directory that downloads and installs the banner role from the git@git.lab.example.com:student/banner Git repository.
The banner role configures banners on Cisco IOS and Juniper Junos managed nodes.
After you create the role requirements file, use either VS Code or the CLI to add, commit, and push the changes to the remote repository.
Switch to the tab in VS Code, or return to your GNOME terminal.
Use the mkdir command to create the roles directory in your project:
[student@workstation simplify-external]$ mkdir rolesIn VS Code, create the roles/requirements.yml file with the following content:
--- - src: git@git.lab.example.com:student/banner scm: git version: main
The src attribute specifies the location of the banner role.
The scm attribute specifies Git as the source code management tool.
The version attribute specifies the use of the main branch of the specified Git repository.
Add, commit, and push the changes to the remote repository.
Use a descriptive commit message, such as Add requirements file.
If you choose to use the CLI, then use the git add, git commit, and git push commands from your GNOME terminal:
[student@workstation simplify-external]$git add roles[student@workstation simplify-external]$git commit -m "Add requirements file"1 file changed, 4 insertions(+) create mode 100644 roles/requirements.yml [student@workstation simplify-external]$git push -u origin exerciseEnumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 6 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (4/4), 422 bytes | 422.00 KiB/s, done. Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 remote: remote: To create a merge request for exercise, visit: remote: https://git.lab.example.com/student/simplify-external/-/merge_requests/new?merge_request%5Bsource_branch%5D=exercise remote: To git.lab.example.com:student/simplify-external * [new branch] exercise -> exercise Branch 'exercise' set up to track remote branch 'exercise' from 'origin'.
From the automation controller web UI, update the Cisco IOS MOTD project resource so that the project uses the exercise branch you created with the requirements file.
Navigate to → and then click the icon for the project.
Enter exercise in the field and then click .
Automation controller immediately attempts to synchronize the project.
The field updates to indicate that the project synchronization succeeded.
(Optional) Click in the field to review the job output.
![]() |
The Cisco IOS MOTD project now includes the requirements.yml file specifying the role dependencies for the ios_motd.yml playbook.
Launch the Cisco IOS MOTD banner job template and verify that the resulting job succeeds.
Verify that MOTD banner is now configured on the iosxe1.lab.example.com managed node.
Navigate to → and then click the icon for the job template. The job displays the following output:
PLAY [Add a MOTD banner on Cisco IOS managed nodes] **************************** TASK [Configure the MOTD banner] *********************************************** TASK [banner : Configure managed node banner] ********************************** included: /runner/requirements_roles/banner/tasks/cisco.ios.ios.yml for iosxe1.lab.example.com, iosxe2.lab.example.com TASK [banner : Create a Cisco IOS banner] ************************************** changed: [iosxe1.lab.example.com] changed: [iosxe2.lab.example.com] PLAY RECAP ********************************************************************* iosxe1.lab.example.com : ok=2 changed=1 unreachable=0 failed=0 ... iosxe2.lab.example.com : ok=2 changed=1 unreachable=0 failed=0 ...
On the workstation machine, connect to the iosxe1.lab.example.com managed node as the student user:
[student@workstation simplify-external]$ssh student@iosxe1.lab.example.comManaged by Ansibleiosxe1.lab.example.com#
Return to the workstation machine:
iosxe1.lab.example.com#exit
Connection to iosxe1.lab.example.com closed by remote host.
Connection to iosxe1.lab.example.com closed.Click → in VS Code to close the /home/student/git-repos/simplify-external directory.
On the workstation machine, run the cd command to return to the /home/student directory:
[student@workstation simplify-external]$ cd