Skip to content

Commit

Permalink
replace non working shell script with python script
Browse files Browse the repository at this point in the history
  • Loading branch information
Grotax committed Feb 10, 2024
1 parent da7eb1d commit 391e602
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
13 changes: 13 additions & 0 deletions roles/batman/files/get_batman_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! python3

import subprocess
import sys
import re

pattern = re.compile(r"(batman-adv)(?:, |\/)(\d{4}.\d).*installed")

dkms = subprocess.check_output(["dkms", "status", "batman-adv"]).decode("utf-8")

result = pattern.match(dkms)

print(result[2], end="")
5 changes: 2 additions & 3 deletions roles/batman/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
ansible.builtin.apt:
name: dkms
- name: Check for currently installed batman-adv
ansible.builtin.shell: |
dkms status batman-adv | egrep 'batman-adv, ([0-9]+\.[0-9]+(\.[0-9]+)?), .*: installed' | cut -d, -f2 | awk '{$1=$1};1'
ansible.builtin.script: files/get_batman_version.py
args:
executable: bash
executable: python3
register: installed_batman_version
when: batman_version is defined
changed_when: false
Expand Down

0 comments on commit 391e602

Please sign in to comment.