-
Notifications
You must be signed in to change notification settings - Fork 284
Set env=None if cmd.run.env dict is empty #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be a workaround for a Salt's bug on Ubuntu.
According to the cmd.run
state docs, the default for env
parameter is exactly None
.
So I think there's no need to mess with default
filer and Boolean operators here, since we have cascade merging of defaults into the postgres
dictionary. Just better to set it in the YAML file as the source of working defaults.
postgres/server/init.sls
Outdated
@@ -56,7 +56,7 @@ postgresql-cluster-prepared: | |||
- name: {{ postgres.prepare_cluster.command }} | |||
- cwd: / | |||
- runas: {{ postgres.prepare_cluster.user }} | |||
- env: {{ postgres.prepare_cluster.env|default({}) }} | |||
- env: {{ postgres.prepare_cluster.env|default({}) or None }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to edit defaults.yaml
instead, like this:
# defaults.yaml
postgres:
...
prepare_cluster:
command: initdb --pgdata=/var/lib/pgsql/data
test: test -f /var/lib/pgsql/data/PG_VERSION
user: postgres
env: Null # Be aware that there's no ``None`` value exists in YAML
And just use - env: {{ postgres.prepare_cluster.env }}
over here.
Hi @vutny Thanks for your feedbacks. Funny null did not work either. Anyway, I have discovered my commit does not fix this issue consistently - there must be some environment issue at play - so rather than travelling down a rabbit hole (its minor issue) .. I'll raise a bug on Salt. My investigation suggest issue arises in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @noelmcloughlin .
It's pity that the fix did not resolve the issue for you.
Now your PR is good anyway, it makes things consistent and readable.
Are you using Vagrant? That error is common when trying to invoke login shell without any pty attached, like in non-interactive SSH session. Setting provisioner shell to pure bash
(instead of bash -l
) sometimes helps.
Hey @vutny Thanks, But to clarify my last message. This commit does not work - "env: null" is throwing pyyaml error for incorrectly formatted yaml, state fails. I can revert the commit or cancel the PR (& raise salt issue instead). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm...
I feel like I became dissipated... I did not read the docs carefully enough.
It says:
env
A list of environment variables to be set prior to execution.
A list! And it definitely fails if set to None
explicitly.
I doubt if it even worked before...
Maybe let's fix this right away by setting an empty list []
?
@@ -16,7 +16,8 @@ postgres: | |||
command: initdb --pgdata=/var/lib/pgsql/data | |||
test: test -f /var/lib/pgsql/data/PG_VERSION | |||
user: postgres | |||
env: {} | |||
# Be aware that there's no ``None`` value exists in YAML |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is no longer necessary as well 😃
Hi @vutny that worked. If okay with you, I'll remove that superfluous comment in another PR (as I cannot rebase commits on this branch off master). Thanks!! P.S. The warning still exists |
@noelmcloughlin , it looks good. No worries. And you could just amend ( |
@vutny Unfortunately rebasing is disabled on branches off saltstack-formulas master. :-(
|
Ah, I thought you're working in your own fork. That's more flexible. Anyhow, let's close out this PR. Would you mind to submit new one containing only relevant changes? |
Rebased as #183 Thanks! |
This PR resolves noisy salt.cmd.run when
cmd.run.env:
is passed empty dictionary.mesg: ttyname failed: Inappropriate ioctl for device
Context is:
Fix verified on Ubuntu.