You can find here the slides and the sample code of my talk "Ansible für Entwickler" that I presented on DevOpsCon in Munich at 6th December 2016.
The code samples are tested with Ansible 2.2.0.0 and serverspec 2.37.2 .
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. That will take some times. - Then copy your public key for the authentication that is needed for a SSH login.
ssh-copy-id -i ~/.ssh/id_rsa vagrant@192.168.33.10
Hint: Public and private keys can be generated with the following command: ssh-keygen
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 folder
ansible
- Call
rake spec
- 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"
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 site.yml