Yay! I did it! W00t FTW
Hello To whom it may concern at Ansible / Red Hat / Atlassian
The following documentation does not demonstrate a working configuration and is misleading:
https://www.ansible.com/integrations/devops-tools/atlassian-bitbucket-pipelines
https://www.ansible.com/integrations/devops-tools/atlassian
https://bitbucket.org/AnsibleByRedHat/ansible-tower-pipelines/src/master/
Below is a working configuration. Please review this and update your documentation accordingly.
With this configuration when a commit happens to the Bitbucket repository, pipeline will call a job from Ansible Tower named “Tower_Test”
Set variables in Bitbucket Pipeline
ID Tower_Test
host 10.10.10.10
username tower_user
password password
Note: select the lock icon when creating the password variable so that it is hidden
In the repo create the following files
bitbucket-pipelines.yml
This is a sample build configuration for the Ansible Tower integration.
You can specify a custom docker image from Dockerhub
for your build environment.
image: python:2.7
pipelines:
default:
script: # Modify the commands below to build your repository.
- apt-get install -y gdebi && sudo gdebi ./expect_5.45.4-2_amd64.deb -y
-
chmod 755 tower.bash
-
chmod 755 tower.exp
-
chmod 755 qtower
-
./tower.bash
Note: repositories available to the python:2.7 image do not include expect. expect and its dependencies are sourced from an asia/pacific Ubuntu mirror. This is less than optimal, please suggest how to make this better? Like a better Docker image.
tower.bash
#!/bin/bash -ex
#configur tower-cli settings
echo “Configuring Tower Settings”
tower-cli config host $host
tower-cli config username $username
tower-cli config verify_ssl false
lets use expect to enter the pasword without echoing and get the Oath2 token from tower
./tower.exp $password
echo " current configuration settings:"
cat ~/.tower_cli.cfg
Let’s run a tower-cli job
tower-cli job launch --job-template $ID --monitor
tower.exp
#!/usr/bin/expect -f
set MYVAR [lindex $argv 0]
set send_slow {1 .1}
set timeout -1
spawn ./qtower
match_max 100000
expect -exact "Password: "
sleep .1
send – $MYVAR
send -s – “\r”
sleep .1
send -s – “\r”
expect eof
qtower
tower-cli login $username
Turn on Bitbucket Pipeline
The resulting pipeline log looks like this
Build setup
pip install ansible-tower-cli
wget http://kr.archive.ubuntu.com/ubuntu/pool/main/t/tcl8.6/libtcl8.6_8.6.8+dfsg-4_amd64.deb2s
wget http://kr.archive.ubuntu.com/ubuntu/pool/universe/e/expect/tcl-expect_5.45.4-2_amd64.deb1s
wget http://kr.archive.ubuntu.com/ubuntu/pool/universe/e/expect/expect_5.45.4-2_amd64.deb1s
apt-get install ./libtcl8.6_8.6.8+dfsg-4_amd64.deb -y9s
apt-get install ./tcl-expect_5.45.4-2_amd64.deb -y<1s
apt-get install ./expect_5.45.4-2_amd64.deb -y<1s
chmod 755 tower.bash<1s
chmod 755 tower.exp<1s
chmod 755 qtower
./tower.bash
Configuring Tower Settings
Configuration updated successfully.
- tower-cli config username tower_user
Configuration updated successfully.
- tower-cli config verify_ssl false
Configuration updated successfully.
spawn ./qtower
Password:
{
“id”: 36,
“type”: “o_auth2_access_token”,
“url”: “/api/v2/tokens/36/”,
“created”: “2018-11-02T02:11:59.819468Z”,
“modified”: “2018-11-02T02:11:59.837189Z”,
“description”: “Tower CLI”,
“user”: 1,
“refresh_token”: null,
“application”: null,
“expires”: “3018-03-05T02:11:59.812174Z”,
“scope”: “write”
}
Configuration updated successfully.
current configuration settings:
[general]
host = 10.10.10.10
username = tower_user
verify_ssl = false
oauth_token = xxxxxxxxxxxxxxxxxxxxxx
- tower-cli job launch --job-template Tower_Test --monitor
Current status: running
------Starting Standard Out Stream------
SSH password:
PLAY [all] *********************************************************************
TASK [Check the date on the server.] *******************************************
changed: [ansible]
changed: [node-1]
…