detecting version of syslog-ng

490 views
Skip to first unread message

Randy Bush

unread,
May 6, 2015, 9:33:43 AM5/6/15
to ansible project
have a playbook bit to distribute syslog-ng.conf to a bunch of servers,
some running syslog-ng 3.3 and some running 3.5. so there are two
different configuration files.

is there a way to detect which version a host is running so i can
distribute the appropriate one? for the moment i have an embarrassing
hack based on host entries :(

randy

---
- hosts: syslog35
roles:
- common
tasks:
- name: push syslog-ng.conf35
copy: src=files/linux/syslog-ng.conf35
dest=/etc/syslog-ng/syslog-ng.conf
mode=644
owner=root
group={{root_group}}
notify: restart syslogng

- hosts: syslog33
roles:
- common
tasks:
- name: push syslog-ng.conf33
copy: src=files/linux/syslog-ng.conf33
dest=/etc/syslog-ng/syslog-ng.conf
mode=644
owner=root
group={{root_group}}
notify: restart syslogng

Yassen Damyanov

unread,
May 8, 2015, 5:59:49 AM5/8/15
to ansible...@googlegroups.com


On Wednesday, May 6, 2015 at 4:33:43 PM UTC+3, Randy Bush wrote:
have a playbook bit to distribute syslog-ng.conf to a bunch of servers,
some running syslog-ng 3.3 and some running 3.5.  so there are two
different configuration files.

is there a way to detect which version a host is running so i can
distribute the appropriate one?  for the moment i have an embarrassing
hack based on host entries :(

I would recommend adding the syslog-ng version to facts using a custom module -- see http://docs.ansible.com/developing_modules.html#module-provided-facts

Your "custom facts module" can be a simple shell script like:

----cut here---
#! /bin/sh
 rsyslogd -v | awk '/^rsyslogd/ {printf("{ \"changed\": false, \"rc\": 0, \"ansible_facts\": { \"rsyslog_ver\": \"%s\" } }\n", $2)}'
----cut here---

(the awk stuff might appear a bit cryptic but what it does is to output valid Json on stdout).

This is for rsyslogd on my machine; you need to have something different for syslog-ng.on yours. (And maybe anticipate that there might not be syslog-ng at all?)
Let know if this helps.
-Yassen

Yassen Damyanov

unread,
May 8, 2015, 6:05:38 AM5/8/15
to ansible...@googlegroups.com
Randy, FYI: the output of that script (after beautifying it a bit):

{

   
"changed": false,
   
"rc": 0,
   
"ansible_facts": {

       
"rsyslog_ver": "5.8.6,"
   
}
}

(The trailing comma in the rsyslog_ver value is redundant but you should get the idea.)

Randy Bush

unread,
May 8, 2015, 10:27:45 PM5/8/15
to Yassen Damyanov, ansible...@googlegroups.com
ok, for the record, here is what i ended up with

---
- hosts: ubuntu:debian

tasks:

- name: run syslog-ng --version
command: syslog-ng --version
register: ver_out
changed_when: false

- name: set ver
set_fact: ver="{{ ver_out.stdout.splitlines()[0]|regex_replace('[^\d.]+', '') }}"

- name: push syslog-ng.conf
copy: src=files/linux/syslog-ng.conf-{{ ver }}
dest=/etc/syslog-ng/syslog-ng.conf
mode=644
owner=root
group={{root_group}}
notify: restart syslogng



randy

Yassen Damyanov

unread,
May 9, 2015, 4:42:53 PM5/9/15
to ansible...@googlegroups.com, yasse...@gmail.com
Very elegant!
-Y.
Reply all
Reply to author
Forward
0 new messages