Hi All How can i store a version of a s/w and store only the version number in . . .

Al West:
Actually the package is rsyslog not rsyslogd - so you can use my first example or you can use regex on a command. Note they give slightly different outputs:

---
- name: Get rsyslogd version on Ubuntu
  hosts: all
  become: true
  gather_facts: no

  tasks:
    - name: Get rsyslogd version
      command: rsyslogd -v
      register: output

    - name: rsyslogd version number
      ansible.builtin.set_fact:
        ver: "{{ output.stdout_lines[0] | regex_search('\\d+(\\.\\d+)+') }}"

    - name: rsyslogd version
      ansible.builtin.debug:
        msg: "rsyslogd version {{ ver }}"

Falcon_B:

Falcon_B:
thats what i wanted. And now I will be able to update the config based on the version

Falcon_B:
can i only get the number? without the content?

Falcon_B:
I am trying to fix with the regex actually but not getting clue how to remove the first two word

Al West:
this is the msg:

msg: "rsyslogd version {{ ver }}"

Just remove the “rsyslogd version” text - or am I missing something?

Falcon_B:
oh sorry. yes. you are right

Falcon_B:

image.png

Falcon_B:
actually checking the input as per the version :slightly_smiling_face:

Falcon_B:
what is the benefit here doing set_fact? I will be able get it in setup?

Falcon_B:
ansible setup module*

Al West:
There is a difference between gather_facts and set_fact

Al West:
gather_facts gets a number of arributes from the host - set_fact defines a fact, like a variable. In this case we have assigned the result of a regex on a string to the ver fact - you won’t get ver from gather_facts

Falcon_B:
okay. Got it here.

Falcon_B:
not possible to get it by set_fact? or setting it in a way so that in future can be retrived

Al West:
I don’t really understand what you are trying to do. Save it to a file if you want it later?

Falcon_B:
no no. just askign. If this version can be set as set fact.

I am trying to change one config. based on that

Falcon_B:

image.png

Al West:
So the fact you set is only ‘alive’ for the playbook run.

Falcon_B:
but this is failig