To test the ansible scripts you can set up a Virtual Machine isolated from your own local system.
A Vagrantfile
has been provided and the usual vagrant
commands should get it up and running.
The following method runs the ansible playbooks on the local connection. Normally you will be running ansible on your development machine, and using it to modify remote hosts.
NOTE The /vagrant/
directory maps to the directory on your host that you launched the VagrantFile
from
e.g. ~/workspace/AdoptOpenJDK/openjdk-infrastructure/ansible
vagrant up
vagrant ssh # Uses default ssh login, user=vagrant, password=vagrant
cd /vagrant/playbooks
Note:
- A
hosts
file containinglocalhost ansible_connection=local
will already be present in the directory with the playbook scripts (/vagrant/playbooks
). - A public key file
id_rsa.pub
will already be present in the/home/vagrant/.ssh/
folder
- Run a playbook to install dependencies, for Ubuntu 14.x on x86:
ansible-playbook -s AdoptOpenJDK_Linux_Playbook/main.yml
or
ansible-playbook -i hosts -s AdoptOpenJDK_Linux_Playbook/main.yml
In case one or more tasks fail or should not be run in the local environment, see Skipping one or more tags via CLI when running Ansible playbooks for further details. Ideally, the below can be run for smooth execution in the vagrant
box:
ansible-playbook -i hosts -s AdoptOpenJDK_Linux_Playbook/main.yml --skip-tags="install_zulu,jenkins_authorized_key,nagios_add_key,add_zeus_user_key"
Yes, in order to access the package repositories (we will perform either yum install
or apt-get
commands)
-
Install Ansible
- On Ubuntu 16.x
apt install ansible
- On RHEL 7.x
yum install epel-release yum install ansible
- For Ubuntu 14.x
sudo apt-add-repository ppa:ansible/ansible sudo apt update sudo apt install ansible
-
Ensure that you have edited the
hosts
in/etc/ansible/
or in the project root directory. For running locallyhosts
file should contain something as simple aslocalhost ansible_connection=local
. -
Run a playbook to install dependencies, e.g. for Ubuntu 14.x on x86:
ansible-playbook -s playbooks/AdoptOpenJDK_Linux_Playbook/main.yml # Or to use a custom hosts file: ansible-playbook -i /path/to/hosts -s AdoptOpenJDK_Linux_Playbook/main.yml
-
The Ansible playbook will download and install any dependencies needed to build OpenJDK
Our playbooks are named according to the operating system they are supported for, keep in mind that package availability may differ between operating system releases
On any machine you have SSH access to: in the playbooks here we are using hosts: local
,
our playbook will run on the hosts defined in the Ansible install directory's hosts
file. To run on the local machine,
we will have the following text in our /etc/ansible/hosts
file:
[local]
127.0.0.1
Running ansible --version
will display your Ansible configuration folder that contains the hosts
file you can modify
One of the two examples below is appropriate to run a playbook and skip tags, leading to linked and dependent tasks to be not executed:
ansible-playbook -s playbooks/AdoptOpenJDK_Linux_Playbook/main.yml --skip-tags "jenkins_user"
ansible-playbook -s playbooks/AdoptOpenJDK_Linux_Playbook/main.yml --skip-tags "install_zulu, jenkins_authorized_key, nagios_add_key, add_zeus_user_key"
The below example is appropriate to run playbook by skipping tasks by using a combination of conditionals and tags (linked and dependent tasks will not be executed):
ansible-playbook -i [/path/to/hosts] -s AdoptOpenJDK_Linux_Playbook/main.yml --extra-vars "Jenkins_Username=jenkins Jenkins_User_SSHKey=[/path/to/id_rsa.pub] Nagios_Plugins=Disabled Slack_Notification=Disabled Superuser_Account=Disabled" --skip-tags="install_zulu"
Note that when running from inside the vagrant
instance:
- the
[/path/to/hosts]
can be replace with/vagrant/playbooks/hosts
- the
[/path/to/id_rsa.pub]
can be replaced with/home/vagrant/.ssh/id_rsa.pub
Useful if one or more tasks are failing to execute successfully or if they need to be skipped due to not deemed to be executed in the right environment.
Below are the levels of verbosity available with using ansible scripts:
ansible-playbook -v -s playbooks/AdoptOpenJDK_Linux_Playbook/main.yml
ansible-playbook -vv -s playbooks/AdoptOpenJDK_Linux_Playbook/main.yml
ansible-playbook -vvv -s playbooks/AdoptOpenJDK_Linux_Playbook/main.yml
ansible-playbook -vvvv -s playbooks/AdoptOpenJDK_Linux_Playbook/main.yml
A snippet from the man pages of Ansible:
-v, --verbose verbose mode (-vvv for more, -vvvv to enable connection debugging)
When the above ansible-playbook
commands succeed, we should get something of this output (snippet):
TASK [Start NTP] ***************************************************************
changed: [localhost]
TASK [Remove unneeded packages from the cache] *********************************
ok: [localhost]
TASK [Remove apt dependencies that are no longer required] *********************
ok: [localhost]
TASK [Send Slack notification, successful] *************************************
skipping: [localhost]
PLAY RECAP *********************************************************************
localhost : ok=49 changed=21 unreachable=0 failed=0