On Tue, 12 Jul 2022 at 08:54, Mohtashim S <[email protected]> wrote:

> The output is for logging and auditing purposes only.
>
> The apps may be run by other teams on their intended hosts as mentioned in
> the inventory file or on other hosts where they should not be running.
>

This confirms my suspicion that this isn't a technical problem but rather
an organisational one.
Since I don't believe in fixing organisational problems with technological
measures, I won't be able to help you with that.
Somebody else might, though.

>
> The dumps would help identify where the app was actually running at the
> time of play and then the play may choose to start / stop the app at the
> intended host.
>
> This is a real-world problem and any solution would be appretiated.
>
> On Tuesday, July 12, 2022 at 9:34:49 AM UTC+5:30 [email protected] wrote:
>
>> Suppose your playbook does what you (think) you want. Then what do you
>> intend to do with this output?
>> What if some apps are running on hosts they're not intended to run on? Do
>> you take some corrective measures? Or reinstall the host?
>> And why is it possible at all that apps appear on random inventory hosts?
>>
>> Rather than using ansible as a glorified shell wrapper to report proces
>> status, I would use it to set up the infra so that only the right apps run
>> on the right hosts.
>>
>>
>> On Tue, 12 Jul 2022 at 00:16, Mohtashim S <[email protected]> wrote:
>>
>>> I have 3 applications hosted on three separate hosts and mentioned in
>>> the hosts file like below:
>>>
>>> cat my.hosts
>>>
>>> [app1_webapp]
>>> host3.mybank.com
>>>
>>> [app2_webapp]
>>> host5.mybank.com
>>>
>>> [app3_webapp]
>>> host8.mybank.com
>>> My requirement is to run two types of raw module commands.
>>>
>>> The first raw task which should run on all three hosts for all three
>>> applications i.e uptime
>>>
>>> The second raw task is ps command that should run only on the respective
>>> host i.e ps -ef | grep app1 should only run on host3.mybank.com
>>>
>>> Below is how I call my main.yml
>>>
>>> ansible-playbook -i my.hosts main.yml -e appname=app1,app2,app3
>>>
>>> cat main.yml
>>>
>>> - hosts: "{{ product(appname.split(',')) |
>>> product(['webapp'])|map('flatten')|map('join', '_') }}"
>>>
>>>   user: user1
>>>   gather_facts: no
>>>
>>>   tasks:
>>>
>>>        - name: Check Running Process
>>>          raw: "ps -ef | grep {{ item }}"
>>>          register: psout
>>>          with_items: "{{ appname.split(',') }}"
>>>
>>>        - name: DUMP Running Process
>>>          debug:
>>>            msg: "{{ psout.stdout }}"
>>>
>>> The above raw fails as it tried ps for each app on each hosts which is
>>> what I wish to skip (correct).
>>>
>>> How do I put a when condition so that the ps command for the respective
>>> app should run on the respective host only and not on all three hosts?
>>>
>>> Summary: my problem is regarding standard practice in infrastructure
>>> management. Each app runs on its own host as specified in the my.hosts
>>> file. I wish to find if the app process ps -ef | grep <app-name> is running
>>> on its own host(desired) and not on all inventory-hosts
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ansible Project" group.
>>>
>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/ef324a05-5da8-41e2-b214-611dfdc9afcbn%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/ef324a05-5da8-41e2-b214-611dfdc9afcbn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> Sent from Gmail Mobile
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c9b56ba9-b861-41f0-82ef-5fd4e333eb2en%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/c9b56ba9-b861-41f0-82ef-5fd4e333eb2en%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
Sent from Gmail Mobile

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLYuZ1H3to1fu10m59-vyMzDrOKAgmf3jBd%3Db1rvzLQ8Pg%40mail.gmail.com.

Reply via email to