You can find here the slides and the sample code of my talk "Ansible für Java-Entwickler" that I presented on JUG Schweiz in Luzern at 15th October 2019.
The code samples are tested with Ansible 2.8.5, ansible-lint 4.1.0, testinfra 3.2.0, serverspec 2.37.2 and Molecule 3.0.
I prepare a Vagrantfile for the setup of the test infrastructure. The only prerequires are that you have to install VirtualBox and Vagrant on your machine. Then follow these steps:
- Open a CLI and go to the location of the file
Vagrantfile
. - Call
vagrant up
. Vagrant will download the necessary image for VirtualBox and it'll prepare ssh key for ansible. That will take some times.
There exists three samples: server setup without roles, server setup with roles, deploy WAR file on an installed Apache Tomcat
- Go to the folder
ansible
- Call
ansible-playbook -i inventories/test -u vagrant setup-db.yml
- Call
ansible-playbook -i inventories/test -u vagrant setup-app.yml
- Go to the folder
ansible
- Call
ansible-playbook -i inventories/test -u vagrant setup-db-roles.yml
- Call
ansible-playbook -i inventories/test -u vagrant setup-app-roles.yml
- Go to the folder
ansible
- Call
ansible-lint *.yml
- Go to folder
ansible
- Call
rake spec
- Go to folder
ansible
- Call
py.test --connection=ansible --ansible-inventory inventories/test -v tests/*.py
- Go to folder
ansible
- Call
molecule test
- Go to the folder
ansible
- Build demo app
cd demo-app-ansible-deploy
mvn clean install
- Call
ansible-playbook -i inventories/test -u vagrant deploy-demo.yml
- Cal URL http://192.168.33.10:8080/demo/
Sample for the Ad-hoc command to stop the tomcat service: ansible -i inventories/test -u vagrant -m command -a "/etc/init.d/tomcat stop"
Sample for the Ad-hoc command to start the tomcat service: ansible -i inventories/test -u vagrant -m command -a "/etc/init.d/tomcat start"
Jenkinsfile
demonstrates how a QA pipeline for Ansible Playbooks could looks like in Jenkins.
The comparision shows how a script for a node.js installation looks in Ansible and in Puppet.
- Go to the location of the
Vagrantfile
- Log on the test server with
vagrant ssh
- Install Puppet package with
sudo apt-get install puppet
- Go to
/vagrant/puppet-vs-ansible/puppet/manifest/
- Install needed Puppet modules with
puppet module install puppetlabs/apt --modulepath ../modules
- Run puppet script with
puppet site.pp --modulepath ../modules
- Go to
puppet-vs-ansible/ansible
- Run ansible script with
ansible-playbook -u vagrant -i "192.168.33.10," setup-nodejs.yml