Table of Contents
Ceenter is a project to demonstrate Ansible Tower IaaS capabilities.
Following scenarios are implemented:
- RHV VM
- Create
- Delete
- GCP VM
- Create
- Delete
- OpenShift Project
- Create
- Delete
Job Template names are in form of:
---
Example: Create VM on GCP platform
Service-VM-GCP-Create
Job Template must accept extra variables defined as part of API Caller.
Playbook names are in form of:
---.yml
Example: Create VM on GCP platform
Service-VM-GCP-Create.yml
Ceenter metadata variables for VM Creation:
Role variable names should be in form: <role_name>_*, so for example disk size in gcp_vm role will be defined as gcp_vm_disk_size_gb.
Steps to prepare local environment.
ansible 2.9+
Configure ansible.cfg: Download ansible-hub token from https://cloud.redhat.com/ansible/automation-hub/token
Save token locally to ~/.ansible/galaxy_token.
Install dependent collections
ansible-galaxy collection install -r ./collections/requirements.ymlDetailed blog about setting up env for automation-hub collections.
Install google.cloud requirements:
yum install python-requests
pip install requests google-authDownload GCP credentials.
ansible-playbook Service-GCP-VM-Create.ymlConfigure GCP:
- Create GCP account
- Create keys for ssh access to GCP VMs
- Generate SSH Keys ssh-keygen -t rsa -f ~/.ssh/gcloud-ansible -C ansible
Create Credentials:
- GCP connection
- GCP machine type for ssh access
- Github
- RHV
Create Project:
- Ceenter Repo (https://github.com/ceenter/ceenter.git)
Create Job Templates:
- GCP Create VM
- RHV Create VM
Authenticate Ansible Tower to Automation-hub:
- Retrieve token at https://cloud.redhat.com/ansible/automation-hub/token
- Update token in Ansible Tower: https://www.ansible.com/blog/installing-and-using-collections-on-ansible-tower
Install awx https://docs.ansible.com/ansible-tower/latest/html/towercli/usage.html#installation.
Tool awx doesn't have any local config file to store credentials, but you can export your credentials in local file.
You can use simple script to auth to Tower and use save auth key:
./utils/awx_login.py <TOWER_HOST> <TOWER_USER> <TOWER_PASSWORD> > ~/.awx_conf.env
source ~/.awx_conf.env
# Test config
awx activity_stream listor create file manually:
cat > ~/.awx_conf.env <<EOF
export TOWER_HOST=${TOWER_HOST}
export TOWER_VERIFY_SSL=False
export TOWER_USERNAME=${TOWER_USERNAME}
export TOWER_OAUTH_TOKEN=${TOWER_OAUTH_TOKEN}
EOFCreate Job Template:
name: GCP VM Create
description: Create VM on GCP
job_type: Run
inventory: localhost
project: Ceenter Repo
Playbook: Service-VM-GCP-Create.yml
credentials: ['gcp-jveverka']
instance_group: Container with google authCreate Survey for Job Template:
Parameters: {"vm_name":"mytest","vm_flavor":"Small","vm_memory":2,"vm_cpu":1,"vm_disk_size":20}name: OCP Project Create
description: Create OCP Project
job_type: Run
inventory: localhost
project: Ceenter Repo
Playbook: Service-OCP-Project-Create.yml
credentials: ['Ceenter OCP Project Manager']
instance_group: Container with [openshift pip dependencies](https://github.com/ceenter/ansible-runner-images)Create Survey for Job Template:
Parameters: {"ocp_project_name":"ceenter_test","ocp_project_display_name":"Test project for Ceenter"}name: OCP Project Delete
description: Delete OCP Project
job_type: Run
inventory: localhost
project: Ceenter Repo
Playbook: Service-OCP-Project-Delete.yml
credentials: ['Ceenter OCP Project Manager']
instance_group: Container with [openshift pip dependencies](https://github.com/ceenter/ansible-runner-images)Create Survey for Job Template:
Parameters: {"ocp_project_name":"ceenter_test"}Additional Container Group on OpenShift
oc create -n tower -f ocp-setup/role-pod-manager.ymloc create -n tower -f ocp-setup/sa-tower-container-group.ymloc create -n tower -f ocp-setup/rb-tower-container-group.yml
Download serviceaccount credentials, e.g. from ui download serviceaccount kubeconfig.
Customize Pod Spec on Instance Group
---
apiVersion: v1
kind: Pod
metadata:
namespace: tower
spec:
containers:
- image: quay.io/ceenter/ansible-runner-google:1.4.6
tty: true
stdin: true
imagePullPolicy: Always
args:
- sleep
- infinityContainer image is build in ansible-runner-images repository.
The API Caller is an example GUI which helps generating the propoer API syntax. Ultimately it may also execute the API call, but not at this stage yet. The metdata for API Caller is under the api-caller folder. The first file is the menu-map.json where the interactive menu options are defined.
Launch Job Service-VM-GCP-Create with curl:
curl -k -X POST --user admin:<PASSWORD> https://<TOWER_URL>/api/v2/job_templates/Service-VM-GCP-Create/launch/Query Job Template Survey fields:
curl -k -X GET --user admin:<PASSWORD> -H "Content-Type: application/json" ${TOWER_HOST}/api/v2/job_templates/Service-VM-GCP-Create/survey_spec/