-
|
When I run a Eg, In the case where the secret does not exist, doing something like host.get_fact(facts.server.Command, "podman secret exists my_secret")Raises a hard error and stops the deployment. Doing try:
host.get_fact(facts.server.Command, "podman secret exists my_secret")
except:
passLets the deployment continue, but:
I can get around this sort of by doing yield StringCommand("podman secret exists {} && podman secret rm {} || exit 0".format(id, id))
yield StringCommand("echo -n '{}' | podman secret create {} -".format(value, id))But it feels a bit ugly... I'm not much of a python programmer, perhaps im just using the try/except wrong? Ideally I could just write try:
host.get_fact(facts.server.Command, "podman secret exists {}".format(id))
# no exception, assume podman cmd exists but secret did not exist
# perhaps except CommandError(exit=1) vs CommandError(not_found) or whatever?
yield StringCommand("podman secret rm {}".format(id))
except:
pass
yield StringCommand(create...) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
You can add Seems the best option is to handle the exit code in the command itself, eg x = host.get_fact(
server.Command,
f"podman secret exists {key} && echo {key} || true"
)
if x != None:
print(f"{key} does exist")
else:
print(f"{key} did not exist")Note that |
Beta Was this translation helpful? Give feedback.
You can add
_success_exit_codes=[0,1]which will allow the command to succeed, but there doesn't seem to be a way to get the exit code of the command.Seems the best option is to handle the exit code in the command itself, eg
Note that
podman secret existsoutputs nothing, ever, behaviour may be different if a command outputs nothing tostdoutbut does write tostderrwhere checking forNonemay not work.