diff --git a/cdist/conf/type/__key_value/explorer/state b/cdist/conf/type/__key_value/explorer/state index 8bdd3a1d..6dfb2031 100755 --- a/cdist/conf/type/__key_value/explorer/state +++ b/cdist/conf/type/__key_value/explorer/state @@ -24,6 +24,12 @@ export key="$(cat "$__object/parameter/key" 2>/dev/null \ export state="$(cat "$__object/parameter/state" 2>/dev/null \ || echo "present")" file="$(cat "$__object/parameter/file")" + +if [ ! -f "$file" ]; then + echo "nosuchfile" + exit +fi + export delimiter="$(cat "$__object/parameter/delimiter")" export value="$(cat "$__object/parameter/value" 2>/dev/null \ || echo "__CDIST_NOTSET__")" diff --git a/cdist/conf/type/__key_value/gencode-remote b/cdist/conf/type/__key_value/gencode-remote index 62cc745d..ad216f51 100755 --- a/cdist/conf/type/__key_value/gencode-remote +++ b/cdist/conf/type/__key_value/gencode-remote @@ -44,7 +44,7 @@ fi case "$state_should" in absent) case "$state_is" in - absent) + absent|nosuchfile) # nothing to do ;; wrongformat|wrongvalue|present) @@ -58,6 +58,9 @@ case "$state_should" in ;; present) case "$state_is" in + nosuchfile) + echo created >> "$__messages_out" + ;; absent) echo inserted >> "$__messages_out" ;; @@ -104,7 +107,11 @@ export exact_delimiter="$exact_delimiter" tmpfile=\$(mktemp "${file}.cdist.XXXXXXXXXX") # preserve ownership and permissions by copying existing file over tmpfile -cp -p "$file" "\$tmpfile" +if [ -f "$file" ]; then + cp -p "$file" "\$tmpfile" +else + touch "$file" +fi awk -f - "$file" >"\$tmpfile" <<"AWK_EOF" BEGIN { # import variables in a secure way .. diff --git a/cdist/conf/type/__key_value/man.text b/cdist/conf/type/__key_value/man.text index dabfe928..de2d7d65 100644 --- a/cdist/conf/type/__key_value/man.text +++ b/cdist/conf/type/__key_value/man.text @@ -53,6 +53,8 @@ inserted:: A new line was inserted changed:: An existing line was changed +created:: + A new line was inserted in a new file EXAMPLES