- name: install packages package: name: - opendkim - opendkim-tools state: latest - name: create dkimkeys directory file: path: /etc/dkimkeys owner: opendkim group: opendkim mode: '700' state: directory - name: generate opendkim key command: cmd: "opendkim-genkey -D /etc/dkimkeys -d {{ domain }} -s {{ dkim_selector }}" - name: rename dkim key file command: "mv /etc/dkimkeys/{{ dkim_selector }}.private /etc/dkimkeys/{{ dkim_selector }}.pem" args: removes: "/etc/dkimkeys/{{ dkim_selector }}.private" creates: "/etc/dkimkeys/{{ dkim_selector }}.pem" - name: make directory for socket inside postfix chroot file: path: /var/spool/postfix/opendkim owner: opendkim group: opendkim mode: '770' state: directory - name: add postfix user to opendkim group user: name: postfix groups: opendkim append: yes - name: deploy configuration template: src: opendkim.conf.j2 dest: /etc/opendkim.conf owner: root group: root mode: '0644' - name: enable opendkim systemd: enabled: yes masked: no name: opendkim - name: restart opendkim service: name: opendkim state: restarted