Emmanuel BENOîT
4a56566c58
* Added pre-commit config * Added yamllint config * Updated example YAML files to match the yamllint config * black'd existing Python code
112 lines
3 KiB
YAML
112 lines
3 KiB
YAML
---
|
|
plugin: reconstructed
|
|
instructions:
|
|
|
|
# Check whether that host is managed
|
|
- action: set_fact
|
|
name: inv__managed
|
|
value: >-
|
|
{{ inv__data is defined
|
|
and inv__data.network is defined
|
|
and inv__data.service is defined
|
|
and inv__data.instance is defined }}
|
|
- when: not inv__managed
|
|
action: stop
|
|
|
|
# Fail when the host name starts with "evil".
|
|
- action: block
|
|
block:
|
|
- when: inventory_hostname.startswith( 'evil' )
|
|
action: fail
|
|
msg: '{{ inventory_hostname }} is obviously evil, skipping.'
|
|
rescue:
|
|
# Do not crash on redeemably evil VMs, but still skip them.
|
|
- when: inv__data.unredeemable is defined
|
|
action: fail
|
|
msg: '{{ reconstructed_error }}'
|
|
- action: create_group
|
|
group: reedmably_evil
|
|
add_host: true
|
|
- action: stop
|
|
|
|
# Only create the managed groups if we *have* managed hosts
|
|
- action: block
|
|
run_once: true
|
|
block:
|
|
- action: create_group
|
|
group: managed
|
|
- loop: [ by_environment, by_network, by_failover_stack, by_service ]
|
|
action: create_group
|
|
group: '{{ item }}'
|
|
parent: managed
|
|
|
|
# Copy inv__data fields to separate inv__ variables
|
|
- loop:
|
|
- component
|
|
- description
|
|
- fostack
|
|
- instance
|
|
- network
|
|
- service
|
|
- subcomponent
|
|
when: inv__data[item] is defined
|
|
action: set_fact
|
|
name: inv__{{ item }}
|
|
value: '{{ inv__data[ item ] }}'
|
|
|
|
# Environment variable and groups
|
|
- action: set_fact
|
|
name: inv__environment
|
|
value: >-
|
|
{{
|
|
inv__data.environment | default(
|
|
( inv__instance == "prod" ) | ternary( "prod", "dev" )
|
|
)
|
|
}}
|
|
- action: create_group
|
|
group: env_{{ inv__environment }}
|
|
parent: by_environment
|
|
add_host: true
|
|
|
|
# Failover stack group
|
|
- action: create_group
|
|
group: >-
|
|
{{
|
|
( inv__fostack is defined )
|
|
| ternary( "fostack_" ~ inv__fostack | default("") , "no_failover" )
|
|
}}
|
|
parent: by_failover_stack
|
|
add_host: true
|
|
|
|
# Network group
|
|
- action: create_group
|
|
group: net_{{ inv__network }}
|
|
parent: by_network
|
|
add_host: true
|
|
|
|
# Service group
|
|
- action: set_var
|
|
name: service_group
|
|
value: svc_{{ inv__service }}
|
|
- action: create_group
|
|
group: '{{ service_group }}'
|
|
parent: by_service
|
|
|
|
# Component group. We add the host directly if there is no subcomponent.
|
|
- when: inv__component is defined
|
|
action: block
|
|
vars:
|
|
comp_group: svcm_{{ inv__service }}_{{ inv__component }}
|
|
block:
|
|
- action: create_group
|
|
group: '{{ comp_group }}'
|
|
parent: '{{ service_group }}'
|
|
# Subcomponent group, or lack thereof.
|
|
- when: inv__subcomponent is not defined
|
|
action: add_host
|
|
group: '{{ comp_group }}'
|
|
- when: inv__subcomponent is defined
|
|
action: create_group
|
|
group: svcm_{{ inv__service }}_{{ inv__subcomponent }}
|
|
parent: '{{ comp_group }}'
|
|
add_host: true
|