0

How can I use Ansible to run the following CloudLinux Imunify360 commands properly on CloudLinux 7 (similar to CentOS7)? I tried different ways to "escape" the colons in the commands and it doesn't run properly, even when a YAML syntax checker showed it's correct.

imunify360-agent config update '{"MALWARE_SCANNING": {"rapid_scan": true}}'
imunify360-agent config update '{"MALWARE_SCANNING": {"default_action": "cleanup"}, "MALWARE_SCAN_SCHEDULE":{"interval": "week"}}'
imunify360-agent config update '{"MALWARE_SCANNING": {"enable_scan_inotify": true}}'

from: https://blog.imunify360.com/new-default-settings-for-imunify360

Note: Imunify360 has a free trial.

1

It turns out single quote works where double quote and backslash didn't.

- name: Enable rapid scan
  command: imunify360-agent config update '{"MALWARE_SCANNING"':' {"rapid_scan"':' true}}'

I learned that folding block scalar (>) is an easy alternative and a good way to avoid escaping.

0

Assuming that you're already planning on executing each command in a separate task, you can just use a folding block scalar (>). While these are typically used for multi-line strings since they replace newlines with a single space, a bonus is that they don't evaluate escape sequences, so nothing needs to be escaped.

However, > alone won't strip the trailing newline character which is where - comes in.

- name: Enable rapid scan
  command: >-
    imunify360-agent config update '{"MALWARE_SCANNING": {"rapid_scan": true}}'

- name: Cleanup scan schedule
  command: >-
    imunify360-agent config update '{"MALWARE_SCANNING": {"default_action": "cleanup"}, "MALWARE_SCAN_SCHEDULE":{"interval": "week"}}'

- name: Enable scan inotify
  command: >-
    imunify360-agent config update '{"MALWARE_SCANNING": {"enable_scan_inotify": true}}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.