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".
|
2022-09-02 20:26:36 +02:00
|
|
|
- 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
|
2022-09-02 20:26:36 +02:00
|
|
|
- action: stop
|
2022-09-02 18:00:22 +02:00
|
|
|
|
|
|
|
# Only create the managed groups if we *have* managed hosts
|
2022-09-17 12:22:40 +02:00
|
|
|
- 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
|
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 }}"
|
2022-09-03 10:40:46 +02:00
|
|
|
parent: by_environment
|
|
|
|
add_host: true
|
2022-09-02 18:00:22 +02:00
|
|
|
|
|
|
|
# Failover stack group
|
2022-09-03 10:40:46 +02:00
|
|
|
- action: create_group
|
|
|
|
group: >-
|
2022-09-02 18:00:22 +02:00
|
|
|
{{
|
|
|
|
( inv__fostack is defined )
|
|
|
|
| ternary( "fostack_" ~ inv__fostack | default("") , "no_failover" )
|
|
|
|
}}
|
2022-09-03 10:40:46 +02:00
|
|
|
parent: by_failover_stack
|
|
|
|
add_host: true
|
2022-09-02 18:00:22 +02:00
|
|
|
|
|
|
|
# Network group
|
|
|
|
- action: create_group
|
2022-09-03 10:40:46 +02:00
|
|
|
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 }}"
|
2022-09-03 10:40:46 +02:00
|
|
|
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
|
2022-09-02 20:26:36 +02:00
|
|
|
action: block
|
|
|
|
locals:
|
|
|
|
comp_group: "svcm_{{ inv__service }}_{{ inv__component }}"
|
|
|
|
block:
|
|
|
|
- action: create_group
|
|
|
|
group: "{{ comp_group }}"
|
2022-09-03 10:40:46 +02:00
|
|
|
parent: "{{ service_group }}"
|
2022-09-02 20:26:36 +02:00
|
|
|
# Subcomponent group, or lack thereof.
|
|
|
|
- when: inv__subcomponent is not defined
|
|
|
|
action: add_host
|
|
|
|
group: "{{ comp_group }}"
|
|
|
|
- when: inv__subcomponent is defined
|
2022-09-03 10:40:46 +02:00
|
|
|
action: create_group
|
|
|
|
group: "svcm_{{ inv__service }}_{{ inv__subcomponent }}"
|
|
|
|
parent: "{{ comp_group }}"
|
|
|
|
add_host: true
|