From cf0493d5b0a33b3f911bc261eda197e6e65630cc Mon Sep 17 00:00:00 2001 From: Kirill Buev Date: Mon, 5 Aug 2024 11:30:14 +0300 Subject: [PATCH] The synthetic 'all' environment branches are now the same length as actual environment branches --- README.md | 13 +++++++++---- pkg/inventory/tree.go | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fd2e86a..769d64b 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,9 @@ In general, if you have a single TXT record for a `HOST` and this record has all @all: |--@all_: | |--@all__: - | | |-- + | | |--@all___: + | | | |--@all____..._: + | | | | |-- |--@all_host: | |--@all_host_: | | |-- @@ -205,9 +207,12 @@ These will produce the following Ansible inventory tree: @all: |--@all_app: | |--@all_app_tomcat: - | | |--app01.infra.local - | | |--app02.infra.local - | | |--app03.infra.local + | | |--@all_app_tomcat_backend: + | | | |--@all_app_tomcat_backend_auth: + | | | | |--app01.infra.local + | | | | |--app02.infra.local + | | | |--@all_app_tomcat_backend_media: + | | | | |--app03.infra.local |--@all_host: | |--@all_host_linux: | | |--app01.infra.local diff --git a/pkg/inventory/tree.go b/pkg/inventory/tree.go index 21d7095..aeefa7e 100644 --- a/pkg/inventory/tree.go +++ b/pkg/inventory/tree.go @@ -64,8 +64,8 @@ func (n *Node) ImportHosts(hosts map[string][]*HostAttributes, sep string) { groupNode := envNode.AddChild(groupName) // Service: root>environment>role>service[1]>...>service[N]. - for i, srv := range strings.Split(attr.Srv, sep) { - if len(srv) > 0 && (i == 0 || env != ansibleRootGroup || attr.Env == ansibleRootGroup) { + for _, srv := range strings.Split(attr.Srv, sep) { + if len(srv) > 0 { groupName = groupName + sep + srv groupNode = groupNode.AddChild(groupName) }