DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Using Ansible Galaxy Roles in Ansible Playbook Bundles

Using Ansible Galaxy Roles in Ansible Playbook Bundles

Learn how Ansible Playbook bundles let you use playbooks to automate the provisioning of services on OpenShift, with the help of Ansible Galaxy.

Siamak Sadeghianfar user avatar by
Siamak Sadeghianfar
·
Sep. 10, 18 · Tutorial
Like (1)
Save
Tweet
Share
6.32K Views

Join the DZone community and get the full member experience.

Join For Free

The Open Service Broker API standard aims to standardize how services (cloud, third-party, on-premise, legacy, etc) are delivered to applications running on cloud platforms like OpenShift. This allows applications to consume services the exact same way no matter on which cloud platform they are deployed. The service broker pluggable architecture enables admins to add third-party brokers to the platform in order to make third-party and cloud services available to the application developers directly from the OpenShift service catalog. As an example AWS Service Broker created jointly by Amazon and Red Hat, Azure Service Broker created by Microsoft and Helm Service Broker created by Google to allow consumption of AWS services, Azure services and Helm charts on Kubernetes and OpenShift. Furthermore, admins can create their own brokers in order to make custom services like provisioning an Oracle database on their internal Oracle RAC available to the developers through the service catalog.

OpenShift Automation Broker is a service broker that is included in OpenShift out-of-the-box and leverages a lightweight, container-based application definition called an Ansible Playbook Bundle (APB) to automate service provisioning using Ansible. The playbooks can perform actions on OpenShift platform, as well as off platform such as provisioning a virtual machine on VMware and installing a database on it.

Ansible Galaxy Roles

The current structure of APBs requires all Ansible roles used in the playbooks to be available in the roles directory, as Ansible normally demands it.

myapb
├── apb.yml
├── Dockerfile
├── playbooks
│   ├── deprovision.yml
│   └── provision.yml
└── roles
    ├── myrole1
    └── myrole2

While that is useful, the power of Ansible lies in the large ecosystem of Ansible roles that are created by third-parties and the community which simplifies automating virtually anything. The expression "there is role for that!" is not far from reality in the Ansible world.

Ansible Galaxy is the hub for finding, reusing and sharing Ansible roles. Whenever one needs to create an Ansible role, the first step is usually to search on Ansible Galaxy for a role that already does the task needed.

Although on the roadmap, currently the Ansible Galaxy roles cannot be directly used in the APB playbooks unless they are already downloaded in the roles directory. Nevertheless, you can still use Ansible Galaxy roles in the APB through a few extra steps which are explained in the next section.

Using Ansible Galaxy Roles in APBs

The first step for using the Ansible Galaxy roles is to list those roles as dependencies in a requirements.yml file in the root of the APB which is the standard way of describing the Ansible Galaxy roles in Ansible:

- src: siamaksade.openshift_sonatype_nexus
  version: ocp-3.9
- src: siamaksade.openshift_gogs
  version: ocp-3.9
- src: siamaksade.openshift_eclipse_che
  version: ocp-3.9-1

The APB directory structure would look like the following:

myapb/
├── apb.yml
├── Dockerfile
├── requirements.yml
├── playbooks
│   ├── deprovision.yml
│   └── provision.yml
└── roles
    ├── myrole1
    └── myrole2

The above requirements.yml file declares that this APB requires the openshift_sonatype_nexus, openshift_gogs and openshift_eclipse_che roles from Ansible Galaxy.

Since Ansible Galaxy is not integrated into APBs yet, the next step is to add a few lines to the APB Dockerfile to install the dependencies when the APB is being built and packaged:

ADD requirements.yml /opt/apb/actions/requirements.yml
RUN ansible-galaxy install -r /opt/apb/actions/requirements.yml

Now you can use the declared roles in your APB action playbooks, for example in the playbooks/provision.yml which is the playbook that runs when an APB is provisioned via the OpenShift service catalog:

  roles:
  - role: ansible.kubernetes-modules
    install_python_requirements: no
  - role: ansibleplaybookbundle.asb-modules
  - role: siamaksade.openshift_sonatype_nexus
  - role: siamaksade.openshift_gogs
  - role: siamaksade.openshift_eclipse_che

Further Integration With Ansible Galaxy

In OpenShift 3.11, APBs will become a first-class citizen of Ansible Galaxy and can be shared and reused conveniently the very same way that Ansible roles are shared and reused in Ansible Galaxy. The OpenShift Automation Broker will be able to discover APBs directly from Ansible Galaxy which means that a developer can publish their APB source code to Ansible Galaxy and the OpenShift Automation Broker will run the source directly on a special APB base image. This will allow developers to test their source code changes without the hassle of rebuilding the full APB container images each time they want to test it.

Furthermore, the integration with Ansible Galaxy would allow automatic resolution of the role dependencies based on the APB metadata and would allow using any role that is published to Ansible Galaxy and declared as a dependency in the metadata, directly in the playbooks.

Summary

APBs enable using Ansible playbooks for automating the provisioning of services on OpenShift and also other platforms. Ansible Galaxy enriches the Ansible experience by providing a large set of pre-built roles that can be used to automate virtually anything. By creating a requirements.yml file and modifying the Dockerfile in an APB, one can take advantage of the Ansible Galaxy roles in authoring APBs and build complex automation flows.

Ansible Galaxy roles play an important role in APB authoring and therefore native Ansible Galaxy support in APBs is planned for future releases of OpenShift, possibly in OpenShift 3.11.

Ansible (software) Galaxy (computational biology)

Published at DZone with permission of Siamak Sadeghianfar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What’s New in the Latest Version of Angular V15?
  • Fargate vs. Lambda: The Battle of the Future
  • Debezium vs DBConvert Streams: Which Offers Superior Performance in Data Streaming?
  • 10 Most Popular Frameworks for Building RESTful APIs

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: