I have just started a new job with a company who use Atlassian tools. Based on the links below I have said to my new company it would be easy for me to set up CI/CD based on Bitbucket pipelines to Ansible Tower. Ansible because I have done some basic training on it.
https://www.ansible.com/integrations/devops-tools/atlassian-bitbucket-pipelines
https://www.ansible.com/integrations/devops-tools/atlassian
that link to
https://bitbucket.org/AnsibleByRedHat/ansible-tower-pipelines/src/master/
I'm a bit of a noob, but I have been hacking at this since Thursday.
I don’t think these scripts as they are documented work.
Like you need to add a "- chmod 755 tower.bash" to the YAML before the script will run
and when it runs all the variables in the script get set to "Configuration updated successfully."
Has anyone seen a working example of a pipeline to Ansible Tower that they could share?
Or should I reconsider my plan?
please see my (way too much detail) posts to:
https://community.atlassian.com/t5/Bitbucket-Pipelines-questions/Bitbucket-pipline-integration-with-Ansible-tower-tower-bash/qaq-p/912864#U914654
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:
- step:
script: # Modify the commands below to build your repository.
- 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.deb
- wget http://kr.archive.ubuntu.com/ubuntu/pool/universe/e/expect/tcl-expect_5.45.4-2_amd64.deb
- wget http://kr.archive.ubuntu.com/ubuntu/pool/universe/e/expect/expect_5.45.4-2_amd64.deb
- apt-get install ./libtcl8.6_8.6.8+dfsg-4_amd64.deb -y
- apt-get install ./tcl-expect_5.45.4-2_amd64.deb -y
- apt-get install ./expect_5.45.4-2_amd64.deb -y
# - 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
+ ./tower.bash
+ echo 'Configuring Tower Settings'
+ tower-cli config host 10.10.10.10
Configuring Tower Settings
Configuration updated successfully.
+ tower-cli config username tower_user
Configuration updated successfully.
+ tower-cli config verify_ssl false
Configuration updated successfully.
+ ./tower.exp $password
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.
+ echo ' current configuration settings:'
+ cat /root/.tower_cli.cfg
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]
...
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.