Initial import of the WIP plugin
This commit is contained in:
commit
17aa8e8c46
5 changed files with 643 additions and 0 deletions
88
example/00-data.yml
Normal file
88
example/00-data.yml
Normal file
|
@ -0,0 +1,88 @@
|
|||
all:
|
||||
hosts:
|
||||
|
||||
localhost:
|
||||
|
||||
# All of this should obviously come from some other inventory plugin.
|
||||
|
||||
evil-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
|
129
example/01-test-reconstructed.yml
Normal file
129
example/01-test-reconstructed.yml
Normal file
|
@ -0,0 +1,129 @@
|
|||
---
|
||||
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".
|
||||
- when: inventory_hostname.startswith( 'evil' )
|
||||
action: fail
|
||||
msg: "{{ inventory_hostname }} is obviously evil, skipping."
|
||||
|
||||
# Only create the managed groups if we *have* managed hosts
|
||||
- loop: [managed, by_environment, by_network, by_failover_stack, by_service]
|
||||
action: create_group
|
||||
group: "{{ item }}"
|
||||
- loop: [by_environment, by_network, by_failover_stack, by_service]
|
||||
action: add_child
|
||||
group: managed
|
||||
child: "{{ item }}"
|
||||
|
||||
# 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 }}"
|
||||
- action: add_child
|
||||
group: by_environment
|
||||
child: "env_{{ inv__environment }}"
|
||||
- action: add_host
|
||||
group: "env_{{ inv__environment }}"
|
||||
|
||||
# Failover stack group
|
||||
- action: set_var
|
||||
name: failover_group
|
||||
value: >-
|
||||
{{
|
||||
( inv__fostack is defined )
|
||||
| ternary( "fostack_" ~ inv__fostack | default("") , "no_failover" )
|
||||
}}
|
||||
- action: create_group
|
||||
group: "{{ failover_group }}"
|
||||
- action: add_child
|
||||
group: by_failover_stack
|
||||
child: "{{ failover_group }}"
|
||||
- action: add_host
|
||||
group: "{{ failover_group }}"
|
||||
|
||||
# Network group
|
||||
- action: set_var
|
||||
name: network_group
|
||||
value: "net_{{ inv__network }}"
|
||||
- action: create_group
|
||||
group: "{{ network_group }}"
|
||||
- action: add_child
|
||||
group: by_network
|
||||
child: "{{ network_group }}"
|
||||
- action: add_host
|
||||
group: "{{ network_group }}"
|
||||
|
||||
# Service group
|
||||
- action: set_var
|
||||
name: service_group
|
||||
value: "svc_{{ inv__service }}"
|
||||
- action: create_group
|
||||
group: "{{ service_group }}"
|
||||
- action: add_child
|
||||
group: by_service
|
||||
child: "{{ service_group }}"
|
||||
|
||||
# Component group. We add the host directly if there is no subcomponent.
|
||||
- when: inv__component is defined
|
||||
action: set_var
|
||||
name: comp_group
|
||||
value: "svcm_{{ inv__service }}_{{ inv__component }}"
|
||||
- when: inv__component is defined
|
||||
action: create_group
|
||||
group: "{{ comp_group }}"
|
||||
- when: inv__component is defined
|
||||
action: add_child
|
||||
group: "{{ service_group }}"
|
||||
child: "{{ comp_group }}"
|
||||
- when: inv__component is defined and inv__subcomponent is not defined
|
||||
action: add_host
|
||||
group: "{{ comp_group }}"
|
||||
|
||||
# Subcomponent group.
|
||||
- when: inv__component is defined and inv__subcomponent is defined
|
||||
action: set_var
|
||||
name: subcomp_group
|
||||
value: "svcm_{{ inv__service }}_{{ inv__subcomponent }}"
|
||||
- when: inv__component is defined and inv__subcomponent is defined
|
||||
action: create_group
|
||||
group: "{{ subcomp_group }}"
|
||||
- when: inv__component is defined and inv__subcomponent is defined
|
||||
action: add_child
|
||||
group: "{{ comp_group }}"
|
||||
child: "{{ subcomp_group }}"
|
||||
- when: inv__component is defined and inv__subcomponent is defined
|
||||
action: add_host
|
||||
group: "{{ subcomp_group }}"
|
Loading…
Add table
Add a link
Reference in a new issue