Some thoughts:
You could probably do {% if x %}key={{x}}{% endif %}
Or even maybe {{ x or default_value }}
But it may be easier and better to just have your system set a reasonable default if the value isn’t set.
Some thoughts:
You could probably do {% if x %}key={{x}}{% endif %}
Or even maybe {{ x or default_value }}
But it may be easier and better to just have your system set a reasonable default if the value isn’t set.
The problem is that there is no reasonable default value for some of these. For instance, uid: there are many disparate systems, some of which have e.g. userA defined on them as uid 503, and others may have userA defined as 505, and neither are more ‘correct’ than the other. I am bringing user distribution management under the ansible umbrella, but don’t want to try to change things like already-existing uids on systems.
More to the point, the user module appears to attempt to implement this behavior, but it will never receive [NoneType]None, only “None”:
def create_user_useradd(self, command_name=‘useradd’):
cmd = [self.module.get_bin_path(command_name, True)]
if self.uid is not None:
cmd.append(‘-u’)
cmd.append(self.uid)
I have worked around it by changing the if self.uid and other parameter checks in user to include and self.uid != “None” for the moment, but it really seems like the module is not receiving these parameters with NoneType as it expects.
Yep, I think the solution here is to make the Ansible “Module Common” code auto convert “None” to None.
Can you please file a ticket for this, I may dig into this tonight but would like to have it tracked.
(That workaround was a terrible idea. I went with your idiom in the playbook instead, for now):
{% if x %}foo=x{% endif %}
Thanks!
I will file a ticket - leaving work now but it’s on my list.
Thanks!