I am using Ansible to automate the oc process -f allresources.yaml | oc apply -f - command. Inside of allresources.yaml template, I have my routes, services, etc... I want to add an additional but optional route to the template. The template will deploy both HTTPS and (optionally) HTTP routes during the oc apply phase. Not always will the developers require an HTTP route, so I want this to be configurable in the repository Jenkinsfile.
The question comes down to this: Is there a way to add a selector/conditional to oc process that will only evaluate resources that match the selector/conditional. Ultimately, Ansible will evaluate Jenkins configuration and determine how to process the oc process command.
Something along these lines:
oc process -f allresources.yaml APP=someapp ENV=dev --ignore="HTTPRoute" | oc apply -f -"
There is no support for conditionals in openshift templates. However, since you're using Ansible, you have lots of options:
You can have multiple templates and apply them conditionally.
You could use Jinja templates via the Ansible
templatemodule instead of openshift templates.If you don't like jinja2 templates, you could do something similar using an external templating tool like jsonnet, for example: