- name: "check whether marker is present for {{ option }}"
  become: yes
  command:
    argv:
    - grep
    - -q
    - "### BEGIN ANSIBLE MANAGED {{ option }} ###"
    - /etc/backuppc/config.pl
  register: marker_present
  check_mode: no
  failed_when: marker_present.rc == 2
  changed_when: no

- name: "create marker for block {{ option }}"
  become: yes
  replace:
    regexp: "^(\\$Conf{{ '{' }}{{ option }}} = [^;]*;)$"
    replace: |-
      ### BEGIN ANSIBLE MANAGED {{ option }} ###
      \1
      ### END ANSIBLE MANAGED {{ option }} ###
    path: /etc/backuppc/config.pl
  when: marker_present.rc == 1
