--- - name: Stop if the package or its checksum was not set ansible.builtin.assert: that: - falco_package_url is match('https://.+\.(deb|rpm)$') - falco_package_sha256 | length == 64 - falco_driver in ['modern_ebpf', 'kmod'] fail_msg: Set falco_package_url and falco_package_sha256, and falco_driver to modern_ebpf or kmod. - name: Download Falco, refusing it if the checksum differs ansible.builtin.get_url: url: "{{ falco_package_url }}" dest: "/var/tmp/{{ falco_package_url | basename }}" checksum: "sha256:{{ falco_package_sha256 }}" mode: "0644" # The package's install script reads these: no prompts, the chosen driver, # and whether rules update themselves. - name: Install it (Debian and Ubuntu) ansible.builtin.apt: deb: "/var/tmp/{{ falco_package_url | basename }}" environment: &falco_env FALCO_FRONTEND: noninteractive FALCO_DRIVER_CHOICE: "{{ falco_driver }}" FALCOCTL_ENABLED: "{{ 'yes' if falco_rules_auto_update else 'no' }}" when: falco_package_url.endswith('.deb') notify: Restart Falco - name: Install it (Red Hat family) ansible.builtin.dnf: name: "/var/tmp/{{ falco_package_url | basename }}" state: present environment: *falco_env when: falco_package_url.endswith('.rpm') notify: Restart Falco - name: Send alerts to syslog as JSON, at or above the minimum priority ansible.builtin.copy: dest: /etc/falco/config.d/50-iac.yaml owner: root group: root mode: "0644" content: | # Managed by Ansible, role falco. json_output: true priority: {{ falco_minimum_priority }} syslog_output: enabled: true notify: Restart Falco # The new file is checked with Falco, after its default rules, before it # replaces the old one. A rule that does not compile fails here and the file # on disk stays as it was. - name: Write the host rules ansible.builtin.template: src: 50-iac-host.yaml.j2 dest: /etc/falco/rules.d/50-iac-host.yaml owner: root group: root mode: "0644" validate: falco -V /etc/falco/falco_rules.yaml -V %s notify: Restart Falco # Falco loads its configuration and every rule, then exits, so a bad setting # in config.d fails here too, before the service restarts. - name: Ask Falco to load everything without starting ansible.builtin.command: falco --dry-run changed_when: false when: not ansible_check_mode - name: Make sure Falco is enabled and running ansible.builtin.service: name: "{{ 'falco-modern-bpf' if falco_driver == 'modern_ebpf' else 'falco-kmod' }}" enabled: true state: started