Ansible Galaxy Command-Create Ansible Roles with Galaxy Commond-DecodingDevOps

Ansible Galaxy Command-Create Ansible Roles with Galaxy Commond-DecodingDevOps

ansible galaxy is a  community website where we can share ansible roles and we can download ansible roles from it freely. You can find thousands of  ansible roles in ansible galaxy website.  https://galaxy.ansible.com/  To download ansible roles or To create a Ansible role structure, we use the ansible-galaxy command.

Search ansible roles with ansible galaxy command

You can search available ansible roles with ansible galaxy search command. It will list all the available roles in galaxy website in your shell.

Syntax:

ansible-galaxy   search   [role name]

in the below i searched for jenkins role it listed nearly 300 roles which are related to jenkins.

[root@ip-172-31-23-64 ~]# ansible-galaxy search jenkins

Found 310 roles matching your search:

 Name                                               Description
 ----                                               -----------
 AAROC.CODE-RADE-build-containers                   Describe your awesome application here.
 AAROC.CODE-RADE-container                          CODE-RADE build containers
 AAROC.CODE-RADE-jenkins-role                       Role to deploy and configure Jenkins
 acceleanu.jenkins                                  Jenkins CI
 aem_design.jenkins                                 Setup jenkins in your environment.
 AerisCloud.repos                                   Manage CentOS yum and Debian apt repositories
 afonsog.k8s_jenkins                                your description
 ajeleznov.install-jenkins                          Installs the Jenkins automation server on Redhat Family Linux using RPM package file.
 akry.jenkins                                       jenkins installer
 alban.andrieu.jenkins-swarm                        A role for installing jenkins-swarm
 alban.andrieu.logstash-settings                    A role for installing logstash configuration
 alban.andrieu.zap                                  A role for installing zap
 alban.andrieu.zfs                                  A role for installing zfs
 AlbanAndrieu.ansible-jenkins-slave-docker          A role for creating docker image for jenkins slaves
 AlbanAndrieu.ansible-nabla                         A role for gathering nabla infrastructure other ansible role
 AlbanAndrieu.ansible-workstation                   A role for installing workstation
 AlbanAndrieu.jenkins_slave                         A role for installing jenkins-slave
 AlbanAndrieu.selenium                              A role for installing selenium
 .........

Find more information about role

after listing of all available roles if you want to know more information about the role like author of the role,github path, number of downloads of that role,..etc. You can use ansible-galaxy info command. ansible-galaxy info command  will give you all the information about that particular role.

Ex:

[root@ip-172-31-23-64 ~]# ansible-galaxy info  aem_design.jenkins

Role: aem_design.jenkins
        description: Setup jenkins in your environment.
        active: True
        commit: 57e3d202cc96644dfed23481fa184ae08b25f670
        commit_message: update molecule test case for docker-jenkins
        commit_url: https://api.github.com/repos/aem-design/ansible-role-jenkins/git/commits/57e3d202cc96644dfed23481fa184ae08b25f670
        company: aem.design
        created: 2019-09-09T00:38:05.529650Z
        download_count: 4
        forks_count: 0
        github_branch: master
        github_repo: ansible-role-jenkins
        github_user: aem-design
        id: 43197
        imported: 2019-12-04T21:52:10.969468-05:00
        is_valid: True
        issue_tracker_url: https://github.com/aem-design/ansible-role-jenkins/issues
        license: Apache 2.0
        min_ansible_version: 2.4
        modified: 2019-12-05T02:52:10.979473Z
        open_issues_count: 1
        path: (u'/root/.ansible/roles', u'/usr/share/ansible/roles', u'/etc/ansible/roles')
        role_type: ANS
        stargazers_count: 0
        travis_status_url: https://travis-ci.org/aem-design/ansible-role-jenkins.svg?branch=master

Download roles from ansible galaxy website

Till now we have seen how to list available roles in galaxy website and how to find more information about the role. Now lets see how to download that role into your system or shell. To download ansible roles from ansible galaxy website we use ansible-galaxy install command.

Syntax:

ansible-galaxy       install    [rolename]

[root@ip-172-31-23-64 ~]# ansible-galaxy install aem_design.jenkins

- downloading role 'jenkins', owned by aem_design
- downloading role from https://github.com/aem-design/ansible-role-jenkins/archive/master.tar.gz
- extracting aem_design.jenkins to /root/.ansible/roles/aem_design.jenkins
- aem_design.jenkins (master) was installed successfully

[root@ip-172-31-23-64 ~]# ls /root/.ansible/roles/
aem_design.jenkins

[root@ip-172-31-23-64 ~]# ls /root/.ansible/roles/aem_design.jenkins/

defaults  meta  molecule  README.md  tasks
[root@ip-172-31-23-64 ~]#

above you can see ansible role will be downloaded into /root/.ansible/roles directory

Create a role with ansible galaxy command

Using ansible-galaxy init command we can create the role. It will create a role template or directory structure for your role, that suitable for submission to Ansible Galaxy website.

Syntax:

ansible-galaxy     init       [rolename]

[root@ip-172-31-23-64 ~]# ansible-galaxy init myrole

- Role myrole was created successfully

[root@ip-172-31-23-64 ~]# ls
anaconda-ks.cfg   myrole  

[root@ip-172-31-23-64 ~]# ls myrole/

defaults  files  handlers  meta  README.md  tasks  templates  tests  vars

Here above you can role is created with the name "myrole" and it has complete role directory structure.

List Dwonloade roles

To list installed/downloaded roles from ansible galaxy website we can use ansible-galaxy list command. it will list only installed/downloaded roles. It will not display any role you created manually or role that created with init command.

[root@ip-172-31-23-64 ~]# ansible-galaxy list

# /root/.ansible/roles
- aem_design.jenkins, master
# /usr/share/ansible/roles
# /etc/ansible/roles

[root@ip-172-31-23-64 ~]#

Delete the role

To delete the installed/downloaded ansible role from yur system we can use ansible-galaxy remove command.

Syntax:

ansible-galaxy      remove     [role name]

[root@ip-172-31-23-64 ~]# ansible-galaxy remove aem_design.jenkins

- successfully removed aem_design.jenkins

Leave a Reply

Your email address will not be published. Required fields are marked *