--- - name: "Enable AllowKey=system.run[*] using lineinfile on zabbix_agent2.conf" hosts: all gather_facts: false become: true tasks: - name: "Use lineinfile module to to enable AllowKey=system.run[*]" lineinfile: path: "/etc/zabbix/zabbix_agent2.conf" firstmatch: true regex: "^(#)?{{item.key}}" line: "{{item.key}}={{item.value}}" state: present insertbefore: '\n^\#\#\# Option\: DenyKey' loop: - { key: "AllowKey", value: "system.run[*]" } - name: "Restart zabbix agent" service: name: zabbix-agent2.service state: restarted