- name: Test if DKIM private key exists shell: grep -c "dkim_private_key_base64" "{{ inventory_dir }}/group_vars/all/passwords.yaml" || true register: dkim_private_key_test_grep - name: Test if DKIM public key exists shell: grep -c "dkim_public_key_base64" "{{ inventory_dir }}/group_vars/all/passwords.yaml" || true register: dkim_public_key_test_grep - name: Create DKIM keys docker_container: name: ddclient image: "{{ docker_registry }}/pwgen" cleanup: true detach: false container_default_behavior: no_defaults command: "sh dkim-key.sh {{ mail_domain | default(domain) }}" register: dkim_container_output when: dkim_private_key_test_grep.stdout == '0' or dkim_public_key_test_grep.stdout == '0' - name: Set ddclient_key set_fact: dkim_keys: "{{ dkim_container_output.ansible_facts.docker_container.Output | from_yaml }}" when: dkim_private_key_test_grep.stdout == '0' or dkim_public_key_test_grep.stdout == '0' - name: Show DKIM private key debug: msg: "ddclient private key: {{ dkim_keys['dkim'][0]['default.private'] | b64decode }}" verbosity: 2 when: dkim_private_key_test_grep.stdout == '0' - name: Show DKIM public key debug: msg: "ddclient public key: {{ dkim_keys['dkim'][0]['default.txt'] | b64decode }}" verbosity: 2 when: dkim_public_key_test_grep.stdout == '0' - name: Write DKIM private key lineinfile: path: "{{ inventory_dir }}/group_vars/all/passwords.yaml" line: "dkim_private_key_base64: \"{{ dkim_keys['dkim'][0]['default.private'] }}\"" when: dkim_private_key_test_grep.stdout == '0' - name: Write DKIM public key lineinfile: path: "{{ inventory_dir }}/group_vars/all/passwords.yaml" line: "dkim_public_key_base64: \"{{ dkim_keys['dkim'][0]['default.txt'] }}\"" when: dkim_public_key_test_grep.stdout == '0'