In this blog, I will show you how easy it is to use an existing ansible collection with YaK.
Ansible Galaxy
Ansible Galaxy is a public repository of Ansible roles. For the sake of this demonstration, I will use middleware_automation.wildfly collection. To install it, in my yakbeta container:
$ ansible-galaxy collection install middleware_automation.wildfly
Starting galaxy collection install process
[WARNING]: Collection at '/workspace/yak/collections/ansible_collections/yak/misc' does not have a MANIFEST.json file, nor has it galaxy.yml: cannot detect version.
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/middleware_automation-wildfly-1.3.1.tar.gz to /workspace/.ansible/tmp/ansible-local-33e3zino9p/tmp9wz1syaj/middleware_automation-wildfly-1.3.1-vcr58mod
Installing 'middleware_automation.wildfly:1.3.1' to '/workspace/yak/collections/ansible_collections/middleware_automation/wildfly'
Downloading https://galaxy.ansible.com/download/middleware_automation-redhat_csp_download-1.2.2.tar.gz to /workspace/.ansible/tmp/ansible-local-33e3zino9p/tmp9wz1syaj/middleware_automation-redhat_csp_download-1.2.2-hx0wj5oi
middleware_automation.wildfly:1.3.1 was installed successfully
Installing 'middleware_automation.redhat_csp_download:1.2.2' to '/workspace/yak/collections/ansible_collections/middleware_automation/redhat_csp_download'
middleware_automation.redhat_csp_download:1.2.2 was installed successfully
Prepare YaK
With the beta version, I have to set YAK_CORE_COMPONENT
environment variable:
export YAK_CORE_COMPONENT=WILDFLY
This will indicate which component instantiation to use in ./configuration/components/
folder. WILDFLY subdirectory will solely contains a variables.yml with following content:
component_type: middleware_webserver/WildFly
yak_manifest_middleware_webserver:
- on_premises/srv-linux-ols-1
Note the component_type
which is defined even if it will not be used in our case.
on_premises/srv-linux-ols-1 is the pointer to a server in the YaK infrastructure definition(i.e. ./configuration/infrastructure/yak_dev_infrastructure/on_premises/
).
Lastly, we can check that inventory is right with aig
(a command alias for ansible-inventory --graph
):
yak@4dce49535dd1:~/yak$ aig
@all:
|--@aws:
|--@azure:
|--@middleware_webserver:
| |--on_premises/srv-linux-wls-ols-1
|--@oci:
|--@on_premises:
| |--on_premises/srv-linux-wls-ols-1
|--@ungrouped:
Deployment
If we don’t want to customize any settings, calling a role is as easy as this command:
ansible-playbook middleware_automation.wildfly.playbook
Output is long, so I am showing only few lines of the beginning:
[WARNING]: running playbook inside collection middleware_automation.wildfly
PLAY [Converge] **************************************************************************************************************************************************************************************************************
Tuesday 18 April 2023 11:12:12 +0000 (0:00:00.064) 0:00:00.064 *********
[started TASK: Gathering Facts on on_premises/srv-linux-wls-ols-1]
TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************
[WARNING]: Platform linux on host on_premises/srv-linux-wls-ols-1 is using the discovered Python interpreter at /usr/bin/python3.6, but future installation of another Python interpreter could change the meaning of that
path. See https://docs.ansible.com/ansible-core/2.14/reference_appendices/interpreter_discovery.html for more information.
ok: [on_premises/srv-linux-wls-ols-1]
Tuesday 18 April 2023 11:12:15 +0000 (0:00:03.323) 0:00:03.388 *********
[started TASK: middleware_automation.wildfly.wildfly_install : Validating arguments against arg spec 'main' on on_premises/srv-linux-wls-ols-1]
TASK [middleware_automation.wildfly.wildfly_install : Validating arguments against arg spec 'main'] **************************************************************************************************************************
ok: [on_premises/srv-linux-wls-ols-1]
Tuesday 18 April 2023 11:12:15 +0000 (0:00:00.067) 0:00:03.456 *********
[started TASK: middleware_automation.wildfly.wildfly_install : Ensures prerequirements are fullfilled. on on_premises/srv-linux-wls-ols-1]
TASK [middleware_automation.wildfly.wildfly_install : Ensures prerequirements are fullfilled.] *******************************************************************************************************************************
included: /workspace/yak/collections/ansible_collections/middleware_automation/wildfly/roles/wildfly_install/tasks/prereqs.yml for on_premises/srv-linux-wls-ols-1
Tuesday 18 April 2023 11:12:16 +0000 (0:00:00.109) 0:00:03.566 *********
...
After a few minutes, playbook completes. Let’s try to reach the administration console.
Unfortunately, URL is not reachable. After some investigations, I noticed that the port is not opened in firewall.
Once the port is opened, I am getting login/password window. Sadly, I don’t know it. I tried to look in the Ansible code of the role, but add-user.sh
is never used which means I have to run it.
After that, I can login into the administration console.
To Summarize
As we have seen using an existing collection a taking advantage of YaK inventory is very easy and consists of only following steps:
- Collection installation
- Set component environment variable
- Call playbook
Regarding middleware_automation.wildfly role itself, I see this as a good role. Nevertheless, I prefer our in-house developed component which, not only, includes firewall configuration and admin user creation, but also dbi services best practices.