Code Monkey home page Code Monkey logo

ansible-talk's Introduction

ansible-talk

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.

Running the Code Samples

The code samples are tested with Ansible 2.10.8, ansible-lint 4.3.7, testinfra 3.2.0, serverspec 2.41.5 and Molecule 3.0.

Setup Test Infrastructure

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:

  1. Open a CLI and go to the location of the file Vagrantfile.
  2. Call vagrant up. Vagrant will download the necessary image for VirtualBox and it'll prepare ssh key for ansible. That will take some times.

Run Ansible Samples

There exists three samples: server setup without roles, server setup with roles, deploy WAR file on an installed Apache Tomcat

Some samples are based on Ansible community collections, that are defined in ansible/collections/requirements.yml

For installing the Ansible community collections, run

ansible-galaxy install -r ansible/collections/requirements.yml
``


#### Run Setup Samples Without Roles

1. Go to the folder `ansible`
2. Call `ansible-playbook -i inventories/test -u vagrant setup-db.yml`
3. Call `ansible-playbook -i inventories/test -u vagrant setup-app.yml`

#### Run Setup Sample With Roles

1. Go to the folder `ansible`
2. Call `ansible-playbook -i inventories/test -u vagrant setup-db-roles.yml`
3. Call `ansible-playbook -i inventories/test -u vagrant setup-app-roles.yml`

#### Run Ansible Lint against Playbooks
1. Go to the folder `ansible`
2. Call `ansible-lint *.yml`

#### Run Serverspec Tests for Setups

1. Go to folder `ansible`
2. Call `rake spec`

#### Run Testinfra Tests for Setups
1. Go to folder `ansible`
2. Call `py.test --connection=ansible --ansible-inventory inventories/test -v tests/*.py`

#### Run Molecule Tests for Setups
1. Go to folder `ansible`
2. Call `molecule test`

#### Run Deploy Sample

1. Go to the folder `ansible`
2. Build demo app

cd demo-app-ansible-deploy mvn clean install

3. Call `ansible-playbook -i inventories/test -u vagrant deploy-demo.yml `
4. Cal URL http://192.168.33.10:8080/demo/

#### Run Ad-hoc Command Sample

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"`

### QA Jenkins Pipeline
`Jenkinsfile` demonstrates how a QA pipeline for Ansible Playbooks could looks like in Jenkins.

### Run Ansible vs Puppet Samples
The comparision shows how a script for a node.js installation looks in Ansible and in Puppet.

#### Puppet Sample

1. Go to the location of the `Vagrantfile`
2. Log on the test server with `vagrant ssh`
3. Install Puppet package with `sudo apt-get install puppet`
4. Go to `/vagrant/puppet-vs-ansible/puppet/manifest/`
5. Install needed Puppet modules with `puppet module install puppetlabs/apt --modulepath ../modules`
6. Run puppet script with `puppet site.pp --modulepath ../modules`

#### Ansible Sample

1. Go to `puppet-vs-ansible/ansible`
2. Run ansible script with `ansible-playbook -u vagrant -i "192.168.33.10," setup-nodejs.yml`

## Further Links
* http://docs.ansible.com/
* https://github.com/willthames/ansible-lint
* https://testinfra.readthedocs.io/en/latest/
* http://serverspec.org/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.