CDKit: Ansible
CDKit is a DevOps framework that helps to deploy mobile apps (iOS and Android) to the app stores (iTunes and Google Play).
Ansible is a configuration manager that let you run scripts (playbooks) on a small to large number of computers.
It's agentless and needs only a SSH connexion to the computers you want to update.
We will use Ansible to install and maintain the Android SDK, Java 8, Fastlane, SonarQube scanner, ImageMagick, etc. on the Go.CD agents
Before you start, you need to have followed the steps to install the Go.CD server and agent(s)
Please refer to this page to install Ansible for your Linux distribution
If you installed previously Homebrew, let's use it to install Ansible with this command:
brew install ansibleAfter you installed Ansible, you need to checkout this repository to the folder /opt/ansible (both Linux or macOS):
[sudo] mkdir /opt/ansible
git clone [email protected]:timoa/cdkit.ansible.git /opt/ansibleIn case of the hosts file has not been packaged with your Ansible installation, you can use the template in this GIT repository or the folder /opt/ansible/hosts.
[sudo] cp /opt/ansible/hosts /etc/ansible/hostsTo save securely your hosts credentials or any other sensitive information (API Keys, etc.), we will use an Ansible Vault.
To create one for the agents, just type this command:
ansible-vault create /opt/ansible/vault_agentsansible_become_pass: {agents user password}
appc_username: {Appcelerator/Axway username (email address)}
appc_password: {Appcelerator/Axway password}
appc_org: {Appcelerator/Axway organisation ID}You can also create one for the GoCD server to apply automatic updates (set the same Vault password):
ansible-vault create /opt/ansible/vault_gocdansible_become_pass: {gocd server user password}Finally, we need to create a text file that will allow Ansible to programmatically open the Vault (ignored by Git)
vi /opt/ansible/.vaultpasswordfilemysupersecurepasswordNow, your need to open the ansible.cfg file to let Ansible knwo that we use a different location for our playbook, roles, etc.
[sudo] vi /etc/ansible/ansible.cfgChange the roles path to /opt/ansible/roles:
[...]
roles_path = /opt/ansible/roles
[...]Uncomment vault_password_file and add the /opt/ansible/.vaultpasswordfile path.
[...]
vault_password_file = /opt/ansible/.vaultpasswordfile
[...]If you want to keep the management of your hosts under a GIT repository, I will suggest that you fork this repository and change this line under your /etc/ansible/ansible.cfg file:
[...]
inventory = /opt/ansible/hosts
[...]If you don't fork this GIT repository and make any changes on the
hostsfile, these changes will be replace by a newer version the next time you update the project with thegit pullcommand in the/opt/ansiblefolder!
To test if everything is ok, you can ping your hosts.
ansible all -m pingOutput:
gocd | SUCCESS => {
"changed": false,
"ping": "pong"
}
agent01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
agent02 | SUCCESS => {
"changed": false,
"ping": "pong"
}
agent03 | SUCCESS => {
"changed": false,
"ping": "pong"
}The Xcode role DOESN'T download or update Xcode. You need to download and store the XPI file on a network drive (NFS, SMB, etc.) or temporary folder before running the following command.
The following command install all the necessary Ansible Roles from Galaxy:
ansible-galaxy install -r /opt/ansible/requirements.ymlHomebrew is the "The missing package manager for macOS" and it will helps to install some software automatically.
You need to run this command in a terminal on each of your Go.CD agents:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"ansible-playbook /opt/ansible/playbooks/homebrew.ymlansible-playbook /opt/ansible/playbooks/android/sdkInstall.ymlansible-playbook /opt/ansible/playbooks/android/emulatorsInstall.ymlansible-playbook /opt/ansible/playbooks/nvm.ymlansible-playbook /opt/ansible/playbooks/titanium/sdkInstall.ymlansible-playbook /opt/ansible/playbooks/appium.ymlansible-playbook /opt/ansible/playbooks/macos.ymlIdeally, you Ansible playbooks need to be run automatically and nothing is simplier than a CRON job for that!
Update the crontab.txt file to fill your own time preferences and run this command:
crontab /opt/ansible/crontab.txtContent of the crontab.txt:
# Ansible - Update Homebrew packages on all agents every day at 1:00 AM
0 1 * * * echo -e " \n #################$(date)################# \n" >> /opt/ansible/logs/homebrew.log ; ansible-playbook /opt/ansible/playbooks/homebrew.yml >> /opt/ansible/logs/homebrew.log
# Ansible - Update Android SDK packages on all agents every day at 2:00 AM
0 2 * * * echo -e " \n #################$(date)################# \n" >> /opt/ansible/logs/androidSdkUpdate.log ; ansible-playbook /opt/ansible/playbooks/android/sdkUpdate.yml >> /opt/ansible/logs/androidSdkUpdate.log
# Ansible - Update Titanium SDK packages on all agents every day at 3:00 AM
0 3 * * * echo -e " \n #################$(date)################# \n" >> /opt/ansible/logs/titaniumSdkUpdate.log ; ansible-playbook /opt/ansible/playbooks/titanium/sdkUpdate.yml >> /opt/ansible/logs/titaniumSdkUpdate.log
# Ansible - Update Appium package on all agents every Monday at 3:15 AM
15 3 * * MON echo -e " \n #################$(date)################# \n" >> /opt/ansible/logs/appium.log ; ansible-playbook /opt/ansible/playbooks/appium.yml >> /opt/ansible/logs/appium.log
# Ansible - Apply macOS Software updates on all agents every day at 3:30 AM
30 3 * * * echo -e " \n #################$(date)################# \n" >> /opt/ansible/logs/macos.log ; ansible-playbook /opt/ansible/playbooks/macos.yml >> /opt/ansible/logs/macos.log
# Ansible - Reboot all agents every day at 5:00 AM
00 5 * * * echo -e " \n #################$(date)################# \n" >> /opt/ansible/logs/reboot.log ; ansible-playbook /opt/ansible/playbooks/reboot.yml >> /opt/ansible/logs/reboot.log- Add instructions for the XCode install
- Add the Terminal app into the macOS Accessibility permission (to launch XCode Organiser)
- Prevent the macOS apps to reopen after a reboot
- Create a script for the XCode update that remove the current version
- Create an Ansible playbook to install/update Genymotion + default VMs
- Create an Ansible playbook to install/update the Go.CD agent software
- Create an Ansible playbook to install/update the Go.CD server software
- Create an Ansible playbook to install/update a your Mac with the same settings as the agents
- Create an Ansible role instead of multiple playbooks + a playbook that will configure what we want ot install/configure