reconstructed/example/01-test-reconstructed.yml

110 lines
2.9 KiB
YAML
Raw Normal View History

2022-09-02 18:00:22 +02:00
---
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
2022-09-04 11:41:52 +02:00
add_host: true
- action: stop
2022-09-02 18:00:22 +02:00
# Only create the managed groups if we *have* managed hosts
- action: create_group
2022-09-02 18:00:22 +02:00
group: managed
- loop: [by_environment, by_network, by_failover_stack, by_service]
action: create_group
group: "{{ item }}"
parent: managed
2022-09-02 18:00:22 +02:00
# 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
2022-09-02 18:00:22 +02:00
# Failover stack group
- action: create_group
group: >-
2022-09-02 18:00:22 +02:00
{{
( inv__fostack is defined )
| ternary( "fostack_" ~ inv__fostack | default("") , "no_failover" )
}}
parent: by_failover_stack
add_host: true
2022-09-02 18:00:22 +02:00
# Network group
- action: create_group
group: "net_{{ inv__network }}"
parent: by_network
add_host: true
2022-09-02 18:00:22 +02:00
# Service group
- action: set_var
name: service_group
value: "svc_{{ inv__service }}"
- action: create_group
group: "{{ service_group }}"
parent: by_service
2022-09-02 18:00:22 +02:00
# Component group. We add the host directly if there is no subcomponent.
- when: inv__component is defined
action: block
locals:
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