Groesbeek, view of the 'National Liberation Museum 1944-1945' in Groesbeek. © Ton Kersten
Fork me on GitHub
Posts tagged as ansible

Runninng it through Tattr (part 2)

2018-08-08 (148) by Ton Kersten, tagged as ansible, sysadm

Some time ago I created a playbook to show the content of a rendered template. When you keep digging in the Ansible documentation, you suddenly stumble over the template lookup-plugin. And then it turns out that my playbook is a bit clumsy.

A nicer and shorter way to do it:

# This playbook renders a template and shows the results
# Run this playbook with:
#       ansible-playbook -e templ=<name of the template> template_test.yml
- hosts: localhost
  become: false
  connection: local

    - fail:
        msg: "Bailing out. The play requires a template name (templ=...)"
      when: templ is undefined

    - name: show templating results
        msg: "{{ lookup('template', templ) }}"

Ansible, loop in loop in loop in loop in loop

2018-06-08 (147) by Ton Kersten, tagged as ansible, loop, sysadm

A couple of days ago a client asked me if I could solve the following problem:

They have a large number of web servers, all running a plethora of PHP versions. These machines are locally managed with DirectAdmin, which manages the PHP configuration files as well. They are also running Ansible for all kind of configuration tasks. What they want is a simple playbook that ensures a certain line in all PHP ini files for all PHP versions on all webservers.

All the PHP directories match the pattern /etc/php[0-9][0-9].d.

Thinking about this, I came up with this solution (took me some time, though) smiley

- name: find all ini files in all /etc/php directories
  hosts: webservers
  user: ansible
  become: True
  become_user: root

    - name: get php directories
        file_type: directory
          - /etc
           - php[0-9][0-9].d
      register: dirs

    - name: get files in php directories
          - "{{ item.path }}"
          - "*.ini"
      loop: "{{ dirs.files }}"
      register: phpfiles

    - name: show all found files
        msg: "Files is {{ item.1.path }}"
        - "{{ phpfiles.results }}"
        - files

The part with the with_subelements did the trick. Of course this line can be written as:

loop: "{{ query('subelements', phpfiles.results, files) }}"

Did you run it through TAttr

2017-08-15 (145) by Ton Kersten, tagged as ansible, sysadm

During my last Ansible training the students needed to create some Ansible templates for them selfs. As I do not want to run a testing template against some, or all, machines under Ansible control I created a small Ansible playbook to test templates.

Read more »

Ansible @ Loadays

2014-04-05 (139) by Ton Kersten, tagged as ansible, sysadm

Last Saturday I attended Loadays in Antwerp, Belgium.

After listening to Jan Piet Mens’s talk about Ansible, I was up for it.

At 11:30 sharp, I started my own presentation for an almost packed room. It’s called “Ansible, why and how I use it” and you can find it on SpeackerDeck.

It was a lovely talk, with a very knowledgeable crowd.

Please, have a look at it and if you have any questions, let me know.

Thanks to the crew for organizing such a lovely event, every year.

Photos of the event where taken by Robert Keerse and you can see them at his Google Plus page. Do enjoy!!

For those of you with a strong stomach, the complete presentation is on Youtube as well. Have a look at the Youtube stream

Ansible @ CfgMgmtCamp

2014-02-05 (138) by Ton Kersten, tagged as ansible

Last couple of days I attended Configuration Managememt Camp in Ghent, Belgium. On Monday morning we started of with presentations of Mark Burgess (CFEngine), Luke Kanies (Puppet) and Adam Jacob (Chef). Good talks about the future of things.

After lunch it got nerdy ans I joined the Ansible room, to see how things went and at 17:00 I started my own presentation for a completely packed room. It’s called ‘Ansible, why and how I use it’ and you can find it on SpeackerDeck.

Later that night we joined the social event and I must say that I was really glad that Toshaan ran out of beer-tickets. Four Triple Karmeliet is more than enough for one evening smiley

The Tuesday was a complete Puppet-day, starting of with a Q-and-A with Luke Kanies. Things started a little slow, but as usual we ran out of time because of the amount of questions.

After stocking up with Belgian Beer the two days ended. Lots of new things learned and to look into. Two days well spent.

Ansible Day in Antwerp

2013-06-29 (136) by Ton Kersten, tagged as ansible

Today I’m attending the first full day Ansible configuration meeting. This meeting is in Antwerp, Belgium, a drive of almost 2 hours. Thanks to Multi Mho (Maurice Verheesen) I didn’t need to drive, he wanted to try out his nice, new car. It drives perfectly and we arrived about 30 minutes early.

For a first meeting of a new tool there where a lot of attendants, amongst others (and I don’t want to forget anybody, so I won’t even try to give a complete list), but below are the people I think that where there.

  • Ton Kersten
  • Maurice Verheesen
  • Christopher Ranschaert
  • Colin Petrie
  • Dag Wieers
  • Inigo Ortiz de Urbina Cazenave
  • Jan Piet Mens
  • Jeroen Hoekx
  • Jochen Moes
  • Joost Ringoot
  • Kevin Clymans
  • Kristof Wevers
  • Lee Van Steerthem
  • Mattias Gees
  • Nic De Muyer
  • Serge van Ginderachter
  • Toshaan Bharvani
  • Vincent Van der Kussen

All very knowledgeable people and nice company to be around.

After Jan Piet talked about Ansible Fest in Boston he supplied us with all the goodies he brought home. We all got…. drum-roll…. 1 sticker each. The T-shirts didn’t show up at the Ansible Fest. Not that bad, because I already have one. Thanks to Jan Piet for the time and effort to get some goodies, even though he couldn’t get them.

After this we started discussing and talking about things to improve Ansible. We all agreed things are great and will be greater by time.

All in all a good day to be at and I would like to thank everybody who attended and who helped organize this day. And last but not least Michael deHaan for creating Ansible.

PS: Also thanks to the guys that brought the beer. The Vicaris Triple is a fantastic one.

Ansible issue playbook

2012-11-23 (130) by Ton Kersten, tagged as ansible

Playing with Ansible I did get the idea to make a nice welcome message when you log in to a server. This message needs to be placed in a file, which is configured in /etc/ssh/sshd_config with the banner option. I call this file /etc/issue.

Of course I want to deploy this file with Ansible, so I first defined an entry in the hosts file. This looks like this:

# Settings for master

# Variables for master
location=cow shed
issueremarks=This is the master Ansible server. Please be carefull!!

and this is parsed through a Jinja2 template which looks like

{{ figlethost.stdout }}

                               -- W A R N I N G --
           System Name : {{ "%-25s"|format(ansible_hostname) }} Location : {{ location }}
           Managed by  : {{ "%-25s"|format(name)             }} Room     : {{ room }}
{% if issueremarks is defined %}
{{ }}
{% endif %}

When combining this all into a playbook this results in

- hosts: all
      - name: install figlet
        yum: pkg=figlet state=latest
      - name: figlet name
        command: /usr/bin/figlet -c -w 80 ${ansible_hostname}
        register: figlethost
      - name: deploy issue file
        template: dest=/etc/issue owner=root mode=0444

As you can see there is a registered variable, called figlethost which contains the hostname parsed through figlet. And putting it all together this gives

                        _ __ ___   __ _ ___| |_ ___ _ __
                       | '_ ` _ \ / _` / __| __/ _ \ '__|
                       | | | | | | (_| \__ \ ||  __/ |
                       |_| |_| |_|\__,_|___/\__\___|_|

                               -- W A R N I N G --
           System Name : master                    Location : cow shed
           Managed by  : Ton Kersten               Room     : ESX5i
            This is the master Ansible server. Please be carefull!!