Create a job template, assign a role to a team so that team members can use that job template, and use that job template to launch a job.
Outcomes
Create a job template.
Assign roles to the job template.
Launch a job from the automation controller web UI.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that automation controller is installed and configured with any necessary resources created in previous exercises.
[student@workstation ~]$ lab start provision-job
Procedure 4.2. Instructions
Review the automation controller resources created by the lab command for this exercise.
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.
Navigate to → and then click the link. This is the Git project that contains the playbooks to set up the database servers.
Review the and fields.
Navigate to → and then click the link for the credential. This is the machine credential used for running tasks on the hosts.
Navigate to → and then click the link. This is the inventory for the database servers.
Review the and tabs. Notice that this inventory has one host group, , and one host, .
Create a new job template to set up the database servers.
Navigate to → and then click → to open the page.
Enter the following details and then click :
| Field | Value |
|---|---|
Database setup
| |
Setup database servers
| |
Assign the Admin role to the Developers team on the Database setup job template.
Navigate to → and then click the Database setup job template link.
Click the tab to manage the permissions for the Database setup job template.
Click to open the dialog box.
Click and then click to display the list of available teams.
Select the Developers team, and then click to display the possible roles to apply.
Select the Admin role and then click . This redirects you to the list of permissions for the Database setup job template, which now shows that all members of the Developers team are assigned the Admin role on the Database setup job template.
Run the Database setup job template as the user daniel, who is a member of the Developers team. This attempt to run the job template fails. You examine the cause of failure in the next step.
Log out as the admin user and log in as the daniel user with redhat123 as the password.
Navigate to → and then click the icon for the Database setup job template.
The job fails. Review the error message in the output.
ERROR! couldn't resolve module/action 'mysql_db'. This often indicates a misspelling, missing collection, or incorrect module path.
...output omitted...Log out of the automation controller web UI.
Review the create_samples_db.yml playbook and examine the reason the job failed.
From a terminal, create the /home/student/git-repos directory if it does not already exist, and then change into it.
[student@workstation ~]$mkdir -p ~/git-repos/[student@workstation ~]$cd ~/git-repos/
Clone the https://git.lab.example.com/git/my_dbservers.git Git repository into the /home/student/git-repos directory.
[student@workstation git-repos]$git clone \>https://git.lab.example.com/git/my_dbservers.gitCloning into 'my_dbservers'... ...output omitted... [student@workstation git-repos]$cd my_dbservers
Review the content of the create_samples_db.yml playbook.
---
- name: Install and create a sample database
hosts: all
become: true
gather_facts: false
tasks:
- name: Ensure MariaDB is installed
yum:
name:
- mariadb
- mariadb-server
- python3-PyMySQL
state: present
- name: Ensure the mariadb service is started and enabled
systemd:
name: mariadb
state: started
enabled: true
- name: Ensure the samples database exists
mysql_db:
name: samples
state: presentIn the step 4.3, the error indicated that the job failure was related to the mysql_db module. The mysql_db module is part of the community.mysql collection, which is not part of the ee-supported-rhel8 execution environment. It was included in Ansible 2.9, so it is part of the ee-29-rhel8 execution environment. This playbook was probably originally written for Ansible 2.9.
Determine which execution environment the Database setup job template is using.
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.
Navigate to → and then click the Database setup job template link.
Click the Automation Hub Default execution environment link.
The page indicates that the execution environment is using the image. The community.mysql collection is not included in this execution environment.
To resolve this issue, modify the Database setup job template to use the Ansible Engine 2.9 execution environment execution environment. This execution environment provides the modules available in Ansible 2.9, including the mysql_db module.
Navigate to → and then click the icon for the Database setup job template.
Click the search icon for .
Select and then click .
Click to save the changes to the job template.
An alternative solution that allows you to continue using the later execution environment is to modify the project to include or retrieve the missing community.mysql Ansible Content Collection, so that it is available to the execution environment.
You could embed the collection in the project’s Git repository, or you could use a requirements.yml file to have the automation controller automatically pull it from Ansible Galaxy. For this to work, you need to make sure the execution environment has all the prerequisites needed by that collection already installed.
You also need to modify the playbook so that instead of calling the module as mysql_db, you call it by its fully qualified collection name, community.mysql.mysql_db.
Rerun the Database setup job template as the daniel user.
Navigate to https://controller.lab.example.com, log out as the admin user, and log in as the daniel user with redhat123 as the password.
Navigate to → and then click the icon for the Database setup job template. After some time, the job launched by the job template succeeds.
Confirm that the job template correctly configured a MariaDB database on the serverd.lab.example.com server.
Open a terminal on the workstation machine, connect to the serverd machine, and become the root user.
[student@workstation my_dbservers]$ssh serverd...output omitted... [student@serverd ~]$sudo -i[sudo] password for student:student[root@serverd ~]#
Confirm that the samples database exists.
[root@serverd ~]#mysql -e "SHOW DATABASES"+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | |samples| +--------------------+
Log out of the serverd machine.
[root@serverd ~]#exitlogout [student@serverd ~]$exitlogout Connection to serverd closed. [student@workstation my_dbservers]$