cdist-troubleshooting.rst 1.73 KB
Newer Older
1 2
Troubleshooting
===============
3

4
Error in manifest is not considered an error by cdist
5 6 7 8 9
-----------------------------------------------------
Situation: You are executing other scripts from a manifest.
This script fails, but cdist does not recognise the error.
An example script would be something like this:

Darko Poljak's avatar
Darko Poljak committed
10 11 12 13 14 15 16 17 18
.. code-block:: sh

    % cat ~/.cdist/manifest/init
    "$__manifest/special"
    % cat ~/.cdist/manifest/special
    #!/bin/sh
    echo "Here is an unclean exiting script"
    somecommandthatdoesnotexist
    echo "I continue here although previous command failed"
19 20 21 22 23 24 25 26

We can clearly see that **somecommandthatdoesnotexist**
will fail in ~/.cdist/manifest/special. But as the custom
script is not called with the -e flag (exit on failure) of shell, 
it does not lead to an error. And thus cdist sees the exit 0
code of the last echo line instead of the failing command.

All scripts executed by cdist carry the -e flag. 
27 28
To prevent the above from happening, there are three solutions available,
two of which can be used in the calling script:
29

Darko Poljak's avatar
Darko Poljak committed
30 31 32 33 34 35 36
.. code-block:: sh

    # Execute as before, but abort on failure
    sh -e "$__manifest/special"

    # Source the script in our namespace, runs in a set -e environment:
    . "$__manifest/special"
37

38 39 40
The third solution is to include a shebang header in every script
you write to use the -e flag:

Darko Poljak's avatar
Darko Poljak committed
41 42 43 44 45
.. code-block:: sh

    % cat ~/.cdist/manifest/special
    #!/bin/sh -e
    ...
Darko Poljak's avatar
Darko Poljak committed
46 47 48 49 50 51 52 53 54 55

Using debug dump helper script
------------------------------
Since cdist stores data to local cache that can be used for debugging there
is a helper script that dumps data from local cache.

For more info see:

.. code-block:: sh

56
    cdist-dump -h
Darko Poljak's avatar
Darko Poljak committed
57 58 59 60 61

Or from cdist git cloned directory:

.. code-block:: sh

62
    ./scripts/cdist-dump -h
Darko Poljak's avatar
Darko Poljak committed
63