You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- name: Check if the key is already present in the DNSdist configuration file
ansible.builtin.shell: |
set -o pipefail && fgrep setKey "{{ default_dnsdist_config_location }}" | sed 's/setKey("\(.*\)")/\1/'
register: dnsdist_grepkey_cmd
changed_when: false
failed_when: false
Using fgrep and sed, it aims to extract and register the argument of setKey() as dnsdist_grepkey_cmd.stdout.
Problem
Since the playbook installs DNSdist in the preceding task, the default config file distributed with DNSdist (link) is read as input, resulting in the following phenomenon.
fgrep setKey in Line 29 matches the following comment in Line 15 of the default config file:
-- setKey("please generate a fresh private key with makeKey()")
Running the command in Line 29 against the default config file gives the following output:
$ set -o pipefail && fgrep setKey dnsdistconf.lua | sed 's/setKey("\(.*\)")/\1/'
-- please generate a fresh private key with makeKey()
(The leading double hyphen -- happens to be preserved because it is not captured by the sed expression.)
The above output ends up as the value of fact dnsdist_setkey:
Truncate the automatically-generated DNSdist config file and re-run the playbook. This causes the command in Line 29 to fail with exit code 1, hence triggering the subsequent task that generates an encryption key from scratch:
ansible.builtin.shell: head -c 32 /dev/urandom | base64
register: dnsdist_setkey_cmd
changed_when: true
Possible Solution
Consider replacing fgrep setKey with grep ^setKey (or possibly grep '^\s*setKey' if indentation is to be expected), to avoid matching lines where the setKey() invocation is prefixed.
The regular expression in the sed script should also be prefixed and suffixed with .* to remove leading and trailing characters around the function:
s/.*setKey("\(.*\)").*/\1/
The text was updated successfully, but these errors were encountered:
This issue pertains to the following task:
dnsdist-ansible/tasks/main.yml
Lines 20 to 32 in ca381db
Using
fgrep
andsed
, it aims to extract andregister
the argument ofsetKey()
asdnsdist_grepkey_cmd.stdout
.Problem
Since the playbook installs DNSdist in the preceding task, the default config file distributed with DNSdist (link) is read as input, resulting in the following phenomenon.
fgrep setKey
in Line 29 matches the following comment in Line 15 of the default config file:-- setKey("please generate a fresh private key with makeKey()")
Running the command in Line 29 against the default config file gives the following output:
$ set -o pipefail && fgrep setKey dnsdistconf.lua | sed 's/setKey("\(.*\)")/\1/' -- please generate a fresh private key with makeKey()
(The leading double hyphen
--
happens to be preserved because it is not captured by thesed
expression.)The above output ends up as the value of fact
dnsdist_setkey
:dnsdist-ansible/tasks/main.yml
Lines 47 to 50 in ca381db
This becomes the encryption key when
dnsdist.conf.j2
is expanded by another task to generate the new config file:dnsdist-ansible/templates/dnsdist.conf.j2
Lines 21 to 26 in ca381db
Workaround
Truncate the automatically-generated DNSdist config file and re-run the playbook. This causes the command in Line 29 to fail with exit code
1
, hence triggering the subsequent task that generates an encryption key from scratch:dnsdist-ansible/tasks/main.yml
Lines 34 to 41 in ca381db
Possible Solution
Consider replacing
fgrep setKey
withgrep ^setKey
(or possiblygrep '^\s*setKey'
if indentation is to be expected), to avoid matching lines where thesetKey()
invocation is prefixed.The regular expression in the
sed
script should also be prefixed and suffixed with.*
to remove leading and trailing characters around the function:The text was updated successfully, but these errors were encountered: