Using Ansible Tower to deploy OpenShift on Azure: episode 3

Create job templates & install machines on Azure

In the third episode of our blog series, we show you how to create a job template containing a survey and finally run our first playbook.

This first playbook includes the following roles:

  • azureCreateTemplate: creates a template to deploy a VM in Azure
  • azureDeployVM: deploys the machine
  • azureGetIP: retrieves the public and private IP and writes it in the hosts file for future launched playbooks
  • azureSetDomainamePrefix: sets the prefix for xxxxx.westeurope.cloudapp.azure.com
  • azureOpenPort: opens port 8443 needed for OpenShift OKD

Check the playbook on Gitlab.

 

A job template combines an Ansible playbook from a project and the settings required to launch it.

In Ansible Tower click on RESOURCES/Template.

Click on the button and choose Job Template.

NAME: OKD Azure Part 1
JOB TYPE: Run
INVENTORY: Localhost
PROJECT: Azure Deployment OKD
PLAYBOOK: playbook.yml
CREDENTIAL: Add the machine credential cluster admin we created in Episode 2
VERBOSITY: 1 (Verbose)

Save

We set the VERBOSITY on level 1 to get some feedback when running our playbooks.

Now you’re able to Add Survey. Surveys set extra variables for the playbook similar to ‘Prompt for Extra Variables’, but in a user-friendly Q&A way. Surveys also allow for validation of user input.

In this survey we are going to add some variables that are necessary for the playbook to run. It is important that you set the exact same variables for ANSWER VARIABLE NAME, because the playbook depends on it and will fail otherwise.

The first variable we need is a prefix. This prefix will be used to deploy the virtual machines on Azure. It will also be used to create the dns.
Example: master0devohn.westeurope.cloudapp.azure.com

This should create a unique dns entry for Azure.

PROMPT: Machine prefix
DESCRIPTION: This prefix will be used both on the machines deployed on Azure, as well as for the dns creation. It must be unique in the .westeurope.cloudapp.azure.com domain
ANSWER VARIABLE NAME: azure_virtualMachineName
ANSWER TYPE: Text
MINIMUM LENGTH: 5       MAXIMUM LENGTH: 50
REQUIRED: checked

+ADD  

 

The second variable is the openSSH public matching the private key we added in episode 2. You can get it via:

PROMPT: ssh public key. This is the key we created in episode 1.
DESCRIPTION: .
ANSWER VARIABLE NAME: ssh_sshPubKey
ANSWER TYPE: Text
DEFAULT ANSWER: <paste the public key>
REQUIRED: Checked

+ADD  

 

The next variable is the Azure resource group that will be used to create the machines.

PROMPT: Azure resource group
DESCRIPTION: The resource group you created on Azure were you want the machines deployed
ANSWER VARIABLE NAME: azure_ResourceGroup
ANSWER TYPE: Text
REQUIRED: Checked

+ADD

 

Now we only need the user and password for Azure and we are done with the survey.

In Ansible Tower click on RESOURCES/Template. On the right, you will see some icons which represent actions you can fire on the template. The first icon is the rocket icon. This will launch your Template.

Click on the rocket icon after the OKD Azure Part 1 template to launch it. You’ll now be presented with the survey you created. Fill in the variables or accept the default and launch the job. Notice that you’ll be redirected to the job it runs.

If the play finishes successfully you will see something like this in the recap:

You should now be able to ssh to your deployed CentOS 7.5 machine:

‘mymachine’ is the name you entered in the survey for Machine prefix.
‘./towerLabKeyPrivate’ is the file you created in episode 2.

What’s next?

This blog post is part of the series “Using Ansible Tower to deploy OpenShift on Azure: a step-by-step guide”. In the next episode we will add two more job templates to our Ansible Tower. So, stay tuned!

devoteam

Contact

Hans Neefs
Senior Consultant Open Source and Open Network Infrastructure Devoteam Belgium