Hi
Maybe idiotic problem but I don’t have clue how to bite it
I have example list of 3 hosts all are needed in inventory. I need to run one task to stop application
Host 1
Host 2
Host 3
app can be stopped only on host 2 and 3 and it need to run once because it will stop for whole landscape. I know that I can create a static var with host name but then any landscape i need to change it.
so I though to eliminate host1 from list and then run only once on one of rest hosts (host2/host3)
I tried to do double block but in first iteration skip host 1 but in second block don’t do anything
I’m running task on group called A
[A]
dbhost1
apphost2
apphost3
task “stop application” should run only on apphost2 or 3 and need to run only once(script stop whole environment )
so I would like to eliminate from “stop application” dbhost1 and then run stop part only on one of apphosts(no different which one)
before stop part there some task running on all of nodes
I have multiple environments so and in each of them also is db and app servers and only app servers can stop
I tried to use
block
block:
run_once: yes
when: ansible_hostname[0] == “a”
but if it will catch DB host it will skip it and then skip block part
I hope is more clear now
You mentioned multiple environments. The suggestion I made before is only sufficient for one environment. In our shop, we use “fully articulated group names” that consist of the problem “domain”, the “environment”, plus host classes as required to specify the hosts without relying on special hostname patterns or other tricks.
In your case, suppose your app is called “xkcd”, and you have environments named “dev”, “tst”, “spt”, and “prd”, each of which contains a db host and a few app hosts. Using our shop’s inventory conventions for the “xkcd” problem domain would result in the inventory below. Though not required, by convention we always use a host’s FQDN as the inventory name (i.e. ansible_fqdn==inventory_hostname). We may also set up an “all” pseudo environment that encompasses all the hosts in the problem domain. It’s occasionally useful in playbooks, and it also helps ensure we’ve created our group hierarchy the way we expect. In particular, if we find we’re having to specify a hostname more than once in a problem domain, we probably have not created the correct hierarchy of sub_groups.
Hi
I solved issue with interfering with inventory
I put stop script on one host and lookup for it and start only on server what have it, that solve issue across. I believe whole landscape i will test it in next weeks to see