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

Falcon_B:
Hi All

How can i store a version of a s/w and store only the version number in a var.
Next would like to update a configuration file based on the version of the s/w

Al West:
Something like:

- set_fact:
    ver: "{{ ansible_facts.packages['wget'][0].version }}"
  when: "'wget' in ansible_facts.packages"

Falcon_B:
I have to run the version command also.

Al West:
Sorry I don’t understand? What version command?

Falcon_B:
for the first part i did like that:-


  • name: Checking the version of the s/w
    gather_facts: no
    hosts: localhost
    tasks:
    • name: rsyslog version is
      ansible.builtin.shell: rsyslogd -v
      register: rsyslog_version

    • name: copy the content and send in a file
      ansible.builtin.copy:
      content: “{{rsyslog_version.stdout_lines}}”
      dest: “/tmp/version_out”

Falcon_B:
as tried to keep only the version id. the output giving much data with http://rsyslog_version.st|rsyslog_version.stdout_line

Falcon_B:

Falcon_B:
i just want to take the version from here

Al West:
I wrote how to get the version. Any other way is less efficient and messy.

Falcon_B:
let me try using your way to get the version only. it will give me only the version?

Falcon_B:
for rsyslogd -v what would be your final command?

Al West:
ah you can’t use this method as rsyslogd is not installed as package - it must come bundled with another package.

Falcon_B:
yeah.

Falcon_B:
that is why I thought of storing it in a register.
can I copy the only version number to a variable ( as stdout giving many entries).

Al West:
use a regex on the output

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