Restructured into a collection
This commit is contained in:
parent
ae58080401
commit
3f38940a9c
12 changed files with 128 additions and 78 deletions
example/inventory
94
example/inventory/00-data.yml
Normal file
94
example/inventory/00-data.yml
Normal file
|
@ -0,0 +1,94 @@
|
|||
all:
|
||||
hosts:
|
||||
|
||||
localhost: {}
|
||||
|
||||
# All of this should obviously come from some other inventory plugin.
|
||||
|
||||
evil-vm:
|
||||
inv__data:
|
||||
network: death
|
||||
service: evil
|
||||
instance: chaos
|
||||
unredeemable: true
|
||||
evil-but-nicer-vm:
|
||||
inv__data:
|
||||
network: death
|
||||
service: evil
|
||||
instance: chaos
|
||||
|
||||
vm00:
|
||||
inv__data:
|
||||
network: dev
|
||||
service: ldap
|
||||
instance: dev
|
||||
component: front
|
||||
fostack: 1
|
||||
vm01:
|
||||
inv__data:
|
||||
network: dev
|
||||
service: ldap
|
||||
instance: dev
|
||||
component: front
|
||||
fostack: 2
|
||||
vm02:
|
||||
inv__data:
|
||||
network: dev
|
||||
service: ldap
|
||||
instance: dev
|
||||
component: back
|
||||
subcomponent: ro
|
||||
fostack: 1
|
||||
vm03:
|
||||
inv__data:
|
||||
network: dev
|
||||
service: ldap
|
||||
instance: dev
|
||||
component: back
|
||||
subcomponent: ro
|
||||
fostack: 2
|
||||
vm04:
|
||||
inv__data:
|
||||
network: dev
|
||||
service: ldap
|
||||
instance: dev
|
||||
component: back
|
||||
subcomponent: rw
|
||||
|
||||
vm05:
|
||||
inv__data:
|
||||
network: infra
|
||||
service: ldap
|
||||
instance: prod
|
||||
component: front
|
||||
fostack: 1
|
||||
vm06:
|
||||
inv__data:
|
||||
network: infra
|
||||
service: ldap
|
||||
instance: prod
|
||||
component: front
|
||||
fostack: 2
|
||||
vm07:
|
||||
inv__data:
|
||||
network: infra
|
||||
service: ldap
|
||||
instance: prod
|
||||
component: back
|
||||
subcomponent: ro
|
||||
fostack: 1
|
||||
vm08:
|
||||
inv__data:
|
||||
network: infra
|
||||
service: ldap
|
||||
instance: prod
|
||||
component: back
|
||||
subcomponent: ro
|
||||
fostack: 2
|
||||
vm09:
|
||||
inv__data:
|
||||
network: infra
|
||||
service: ldap
|
||||
instance: dev
|
||||
component: back
|
||||
subcomponent: rw
|
112
example/inventory/01-test-reconstructed.yml
Normal file
112
example/inventory/01-test-reconstructed.yml
Normal file
|
@ -0,0 +1,112 @@
|
|||
---
|
||||
plugin: tseeker.reconstructed.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
|
Loading…
Add table
Add a link
Reference in a new issue