Ansible Galaxy

Ansible Galaxy
Techiio-author
Written by Nilima PaulJanuary 23, 2022
11 min read
Ansible
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Nilima Paul

Technology Security Analyst

We will know in this article, what's the Ansible Galaxy.

Introduction to Ansible Galaxy

Ansible Galaxy is electronic on the web and open-source store for sharing and observing Ansible substance generally jobs and assortments. Maybe we have made a novel, new thing and needed to impart to other people, transfer it to Ansible Galaxy or, then again on the off chance that we have any issues connected with Ansible robotization or need a pre-bundled arrangement given by others to rapidly kick off our computerization projects, we can think that it is on Ansible Galaxy. It very well may be jobs, modules, modules, or assortments. There are as of now numerous local area creators who play transferred their Ansible parts, assortments, and so forth

We use 'ansible-universe' order to achieve undertakings like the establishment of jobs from Galaxy or any git SCM, making new jobs, eliminating jobs, or performing assignments on the Galaxy site. This order is as of now packaged with Ansible so we can utilize it just in the wake of introducing Ansible. World undertaking is an open-source project so we can have our interior Galaxy server. To utilize the inward Galaxy server, we want to abrogate the default design in our ansible. cfg document with server address of our Galaxy inside the server as naturally, it utilizes server address

How to work with Roles or Collections in Ansible Galaxy?

Let us study some roles:

1. Roles

We use the ‘ansible-galaxy’ command to install the roles from the Galaxy server as below:

Code:

ansible-galaxy install <role_name>

Output:

ansible-galaxy install singleplatform-eng.users

Explanation: In the above model, it downloads the 'clients' job, possessed by single-stage eng, and introduces it. 'ansible-universe' order introduces jobs to the default catalog that is '/and so on/ansible/jobs' anyway to introduce jobs to a particular index, we can do it by utilizing one of the three strategies.

The first one is to use –roles-path option while installing the roles as below:

Code:

ansible-galaxy install --roles-path <directory_path><role_name>

Output:

ansible-galaxy install --roles-path /ansible-roles singleplatform-eng.users

Explanation: – In the above example, it installs the role in the/ansible-roles directory. If the directory does not exist then it will be created by the command itself. We can install the same role multiple times with different paths each time.

The second one is to set the environment variable ‘ANSIBLE_ROLES_PATH’. We can set a single directory path or list of paths however it installs roles to the first writable path.

Code:

export ANSIBLE_ROLES_PATH=/anisble-roles
ansible-galaxy install singleplatform-eng.users

Explanation: – In the above command, it installs the role to the directory defined in the configuration file, however, if the environment variable is also defined then it will take precedence.

If there is a requirement to install a specific version of any role, we can do so by using a comma after the role name as below:

Code:

ansible-galaxy install <role_name>,<role_version>

Output:

ansible-galaxy install singleplatform-eng.users,v1.2.5

Explanation: – In the above example, it downloads v1.2.5 as specified in the command. If roles already exist with a different version, use –the force command to change the version or remove the old role before installing a different version of the role.

We can list the installed roles using the ‘list’ command as below:

Code:

ansible-galaxy list

Explanation: – In the above example, it shows installed roles in the directory /ansible-roles that is defined in the environment variable, roles-path rules will apply in the same way to list the roles, we can even use –roles-path option to display the roles installed in a specific directory.

We can install multiple roles from a single YAML file. We can define one or more attributes like src, SCM, version, name, etc.

Code:

cat role_file.yaml
#from galaxy

Output:

ansible-galaxy install -r role_file.yaml
-src: singleplatform-eng.users

Explanation: – In the above example, we define only src and give the name of the role so it will check in the galaxy and install the roles if available. We can install roles from other sources like GitHub, Bitbucket, etc., and specify other attributes as well like version, name, etc.

We can create our roles using the init command as below:

Code:

ansible-galaxy init <role_name>

Output:

ansible-galaxy init my_role

Explanation: – In the above example, it creates a role named ‘my_role’. It creates a folder structure for our roles.

There are the essential commands that we discussed above however there are other operations we can perform on roles. We can use the ‘–help’ command as below to know more about it:

Code:

ansible-galaxy role --help

2. Collections

We can install a collection from Galaxy as below if the internal server is not defined in the configuration file.

Code:

ansible-galaxy collection install <collection_name>

Output:

ansible-galaxy collection install newswangerd.collection_demo

Code:

ansible-galaxy collection install <collection_name>:==<version>

Output:

ansible-galaxy collection installnewswangerd.collection_demo:==1.0.6

Explanation: – In the above example, it installs version 1.0.6 of a collection called newswangerd.collection_demo. We need to specify –the force option to override the collection if already exists.

We can even specify a range to install the most recent version within that range. For detailed information please check official documents. We can install collections using the YAML file as well and specify directives like name, version, source, etc. as we do it for roles.

Code:

---
collections:
#with collection name and version options
- name: alikins.collection_inspect
version: ‘>0.0.9,<1.0.0’

Explanation: – In the above example, it uses a YAML file to install collection and we have specified the range in version directives. As per our range, it will install the most recent version that is greater than ‘0.0.9’ and less than ‘1.0.0’. If we check on the Galaxy website, it has only one version ‘0.0.49’ that falls in our range so it installs that version.

We can create our collection in the same way we create roles as below: –

Code:

ansible-galaxy collection init my_namespace.my_collection

Code:

ansible-galaxy collection -h

Conclusion

There are around 20K people group creators on Ansible universe and around 24K jobs and 281 assortments accessible to launch our robotization project rapidly. There is likewise Developer's Guide for advancement work process and Contributor Guide that go through the course of how one can supporter of the current 'Ansible Galaxy' code as it is an open-source project. It is a concentrated archive for finding and sharing Ansible jobs and assortments.

Ansible
Ansible Galaxy
ubuntu
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Nilima Paul
Technology Security Analyst
Techiio-followerTechiio-followerTechiio-follower
201 Blog Posts
0 Discussion Threads
Trending Technologies
15
Software40
DevOps48
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance