Skip to content

Instantly share code, notes, and snippets.

View Anthonyhawkins's full-sized avatar

Anthony Hawkins Anthonyhawkins

View GitHub Profile
def prune_empty(items):
return list(filter(None, items))
config = {
"foo": "bar",
"biz": "baz",
"stuff": prune_empty([
"a",
Include.when("site-x" in ["site-a", "site-b", "site-c"], "b"),
"c",
"d"
])
}
config = {
"foo": "bar",
"db_backend": Include.when(env("SITE") in ["site-a", "site-b", "site-c"], "10.2.3.4", "10.6.3.4"),
"biz": "baz",
}
config = {
"foo": "bar",
"biz": "baz"
} | Include.when("site-x" in ["site-a", "site-b", "site-c"], {
"enable_x": True
})
class Include(object):
@staticmethod
def when(expression, if_block, else_block={}):
return if_block if expression else else_block
{
"foo": "bar",
if env in ["site-a", "site-b", "site-b"]:
"enable_x": true,
"biz": "baz"
}
foo: bar
#@ if data.values.environment in ['site-a', 'site-b', 'site-c']:
enable_x: true
#@ end
biz: baz
[
# Non-Looped elements
] + [
{
"foo": item
} for item in [
"x", "y", "z"
]
] + [
# Non-Looped elements
jobs:
- name: create-orgs
plan:
...
- task: create-orgs
image: cf-mgmt
config:
...
params:
...
"jobs": [
{
"name": cf_mgmt_command,
"plan": [
...
{
"task": cf_mgmt_command,
"image": "cf-mgmt",
"config": {
...