appuio / ansible-module-openshift

Ansible Modules for Configuring OpenShift 3
Apache License 2.0
3 stars 1 forks source link

Setting resource template argument to "omit" does not omit argument #5

Open hansmi opened 6 years ago

hansmi commented 6 years ago

I have a template with default values for its parameters, i.e.:

kind: Template
apiVersion: v1
…
parameters:
- name: WEB_USERNAME
  generate: expression
  from: '[a-zA-Z0-9]{40}'

When the value is not set in Ansible I intend to omit the values and automatically generating a value:

- openshift_resource:
    namespace: …
    template: "{{ tempdir }}/template.yml"
    app_name: …
    arguments:
      WEB_USERNAME: "{{ foobar_username | default(omit) }}"

I'd expect WEB_USERNAME to be omitted. What happens, however, is that the variable is set to the omit placeholder (__omit_place_holder__…):

# oc -n … export secret …-config 
apiVersion: v1
data:
  WEB_USERNAME: X19vbWl0X3BsYWNlX2hvbGRlcl9fZDk0NWZkMDgyMTJiNDQwNmJiY2E1YjViMzI5ZWJkNTExYjAwZDExNg==
…
dtschan commented 6 years ago

Added support for omitting template arguments in 1f430f737ecd027c2ecd52eac71d407915b052e6. Please note that the module is currently not idempotent when using generators since each template instantiation creates a different value. I currently use something like this to achieve idempotency with generated arguments:

- name: Create MySQL password
  shell: "umask 077 && dd if=/dev/urandom bs=15 count=1 | base64 -w0 > /etc/origin/master/zabbix-monitoring-mysql-password.txt"
  args:
    creates: /etc/origin/master/zabbix-monitoring-mysql-password.txt

- name: Load MySQL password into variable
  slurp:
    src: /etc/origin/master/zabbix-monitoring-mysql-password.txt
  register: mysql_password

- name: Instantiate Zabbix monitoring template
  openshift_resource:
    arguments:
      MYSQL_PASSWORD: "{{ mysql_password['content'] | b64decode }}"