Ansible Syntax Errors

Hello, I am new to Ansible and currently writing my first playbook with the purpose of installing and configuring clamav on a list of servers. Note I am using $localhost for testing. Here is the script:


  • name: Install clamav
    hosts: localhost
    become: yes
    tasks:
    • name: Package installation
      ansible.builtin.yum:
      name:
      clamav-server
      clamav-data
      clamav-update
      clamav-filesystem
      clamav
      clamav-scanner-systemd
      clamav-devel
      clamav-lib
      clamav-server-systemd
      state: latest

    • name: Set antivirus_can_scan_system on and keep it persistent across reboots
      ansible.posix.seboolean:
      name: antivirus_can_scan_system
      state: yes
      persistent: yes

    • name: Set clamd_use_jit on and keep it persistent across reboots
      ansible.posix.seboolean:
      name: clamd_use_jit
      state: yes
      persistent: yes

    • name: Edit the configuration file
      lineinfile:
      path: /etc/clamd.d/scan.conf
      regexp: '#(\s+)LocalSocket /var/run/clamd.scan/clamd.sock'
      replace: 'LocalSocket /var/run/clamd.scan/clamd.sock'
      backup: yes

    • name: Remove from configuration file
      lineinfile:
      path: /etc/clamd.d/scan.conf
      regexp: '#(\s+)Example'
      replace: 'Example'
      backup: yes

    • name: Edit freshclam configuration file
      lineinfile:
      path: /etc/freshclam.conf
      regexp: '#(\s+)Example'
      replace: 'Example'
      backup: yes

    • name: Enable Freshclam
      ansible.builtin.service:
      name: freshclam
      state: started
      enabled: yes

    • name: Ensure ClamAv service is started and enabled
      ansible.builtin.service:
      name: clamd@scan
      state: started
      enabled: yes
      ...

I get the following when I try to run the playbook:

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not
match 'all'
ERROR! couldn't resolve module/action 'ansible.posix.seboolean'. This often indicates a misspelling, missing collection, or incorrect module path.

The error appears to be in '/etc/ansible/kc_first_playbook.yml': line 21, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  • name: Set antivirus_can_scan_system on and keep it persistent across reboots
    ^ here

Any help on this will be appreciated. Thanks!

welcome, we hope you find the forum friendly and helpful.

NB: I am NOT an ansible user !

Please, use the markdown menu options to quote text/messages/code - i've done this for you this time, but going forwards you need to do that.

suggest you read the docs, check syntax etc ...
https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html#using-check-mode

The ansible online docs are really good...

Which release of ansible are you using?
If you're on the latest release you may need to install the ansible.posix.seboolean module as it is not part of the core anymore.
https://docs.ansible.com/ansible/latest/collections/ansible/posix/seboolean_module.html

When identifying the target hosts you should use an inventory file rather than calling them inline the default is /etc/ansible/hosts, this can be overridden with the -i parameter to the command.
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#inventory-basics-formats-hosts-and-groups

1 Like