you could just have - hosts: all and call the playbook via --limit
stagec-webs,
or let your script read a parameter from a file or environement variable
which specifies the environment you want the inventory to be generated and
only generate the inventory for that specific environment.

- Benno


On Thu, Jun 4, 2015 at 10:25 PM, Samnang Sen <[email protected]> wrote:

> We pull our server inventory from a Netscaler. Servers that are binded to
> a specific LB group is considered active and we deploy code and/or restart
> services at when needed. I've written a Python script that outputs the
> hosts into JSON format for Ansible to work with. This works fine except I'm
> at a lost as to how I can handle multiple environments.
>
> It could be the way I output the JSON because I query for ALL servers
> across the three environments we have (stagec, stagef and prod). Do I need
> a separate script for each environment in order to generate a "web" group
> for a particular environment? In my "restart.yml" file, you'll notice I
> intend to run the task against the server group called "webs."
>
> A simple task to restart Apache on just the web servers:
>
> # restart.yml
>
> - name: Graceful restarts on web servers
>   hosts: webs
>   remote_user: deployment
>   sudo_user: deployment
>   gather_facts: no
>
>   roles:
>   - { role: restarts }
>
>
> # roles/restarts/tasks/main.yml
>
> - name: Restart web servers
>   command: sudo /usr/local/apache/bin/apachectl restart
>
> Here's the JSON output from my inventory script:
>
> {
>     "stagec-webs": {
>         "hosts": [
>             "webstage3",
>             "webstage4"
>         ]
>     },
>    "stagec-perl": {
>         "hosts": [
>             "perlstage3",
>             "perlstage4"
>         ]
>     },
>    "stagef-webs": {
>         "hosts": [
>             "webstage9",
>             "webstage5",
>             "webstage1",
>             "webstage2"
>         ]
>     },
> }
>
>  --
> 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 post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/0eca8f66-6d4e-4e88-8f58-b6376dd2a056%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/0eca8f66-6d4e-4e88-8f58-b6376dd2a056%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFUV_d4NxpVm8CMZVFcPmz9QBTwx9WoOrG0jXWt%2BuB_jUf5wLQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to