End-to-End: Python + YAML -to- GitHub -to- Ansible Tower

A few notes on creating a new GitHub repo, initial sync, adding some folders with Python scripts and YAML files, and getting these to run in Ansible.

Step 1: Creating a New Repo with Team Permission

1) Login to your GitHub account.

For example: https://github.com/our-team-git

2) Create a new repository:

  • Owner / Repository name
    • our-team-git / new-repo
  • Private
  • Initialize this repository with: Add a README file
  • Click: Create repository
3) new-repo > Settings > General > Collaborators and teams

Add your team as Admin (pre-requisite is that your team exists in GitHub - if not it is very easy to create a team.)

Step 2: Initial Git Sync to Local and Adding Stuff

Open up Git CMD and navigate to your projects folder (C:\Projects in my example):


Run the command:

git clone https://github.com/our-team-git/new-repo

The new-repo will be your Ansible Tower project.
The sub-folders in new-repo will be your Ansible Tower templates.

In Windows explorer, navigate to your new folder and create additional folders inside new-repo and add your YAML files and Python files inside those folders

For example:
  • C:\Projects\new-repo
    • AnsibleTemplateOne
      • main.yml
      • AnsibleTemplateOne.py
    • AnsibleTemplateTwo
      • main.yml
      • AnsibleTemplateTwo.py
Step 3: Sending to GitHub

In git-cmd, cd to your new-repo and run these commands:
  • # Add recent changes to reference:
    • git add *
  • # Commit code locally:
    • git commit -m "NEW STUFF"
  • # Pull changes that other developer would have committed:
    • git pull
  • # Push changes that you made:
    • git push

And you can validate in github that you new files and folders exist.

Step 4: Create a New Ansible Tower Project

Ansible Tower > Projects > + (to create a new project)

Fill in the details, for example:
  • NAME = new-repo
  • DESCRIPTION = a place to put new-repo integrations
  • ORGANIZATION = {Choose your organization}
  • SCM TYPE = Git
    • SCM URL = https://github.com/our-team-git/new-repo
    • SCM BRANCH/TAG/COMMIT = master / main (see in GitHub)
    • SCM REFSPEC =
    • SCM CREDENTIAL = {Pick a credential with permission to the github repo}
    • SCM UPDATE OPTIONS:
      • Tick: UPDATE REVISION ON LAUNCH
  • ANSIBLE ENVIRONMENT = Use Default Environment
  • Click SAVE
Step 5: Create a New Ansible Tower Job Template

Click on your newly  created Ansible Tower Project and go to the JOB TEMPLATES tab. The click on + to add a new Job Template.

Apart from default settings:
  • NAME: Template Name
  • DESCRIPTION: Template Description
  • JOB TYPE: Run
  • INVENTORY: {Select your Inventory}
  • PROJECT: {Select your Project}
  • PLAYBOOK: {Select your Playbook}
  • CREDENTIALS: {Select your Credential} (different to the SCM Credential used above)
  • LIMIT: {Limit to an Ansible host if you want}
Click SAVE

Click on LAUNCH to test it!

Troubleshoot if there are any issues (i.e. it fails to launch or runs too fast.)

Step 6: Create Schedules for the Ansible Tower Job Templates

SCHEDULES tab and + to add a schedule to automate the task.

THE END

Comments