I am new to Ansible and googleing around i see how to install ClamAV using Ansible , but is there a way to just get the current version , I know I could just run it remotely via ssh
3 Answers
You can use the shell command to get the version then output it through stdout using the register and debug command like so:
- name: check clamAV version
shell: clamscan -V
register: ClamVersion
- debug: msg="{{ ClamVersion.stdout }}"

- 21
- 1
-
So is that a ansible script? how do you execute it? – R.Merritt Jan 29 '20 at 15:18
-
1I would suggest looking into how you create an ansible playbook and running it against a host machine as that is one of the first things you would learn if your starting with the basics. Then you can just add that code in the playbook and it should run. – DarkEvE Jan 31 '20 at 10:49
-
ok great will do – R.Merritt Jan 31 '20 at 15:11
As an alternative, configure software repos to have the version you want, then install it with the OS package manager.
- name: Install ClamAV
package:
state: present
name:
- clamav
- clamd
- name: Enable ClamAV service
service:
name: clamd
enabled: True
Search Galaxy for clamav for more ideas.

- 32,050
- 2
- 19
- 34
DarkEVE's answer includes Tasks that would go inside a Playbook, which is useful if this is going to be a repeatable task.
If you only need to do this once, you can execute the same from ansible command-line (cli):
ansible -m shell -a 'clamscan -V' [target host or group]
This invokes the built-in shell
module (-m), and passes your command as the args (-a).
Depending on your ansible Inventory, you can target a specific host or a group that you have set up -- this is great, as you can quickly see the version across a large number of hosts in a single command. (You can target a group with the Playbook also, of course).
I find using this one-off ansible method is faster/easier than ssh'ing into targets, and certainly much faster when you have to check the same thing on more than one target.

- 53
- 1
- 1
- 6