The "add host" module is currently coded as something called a "bypass host
group" module, which means it only runs once.

This means it's meant to be used in plays that look like this:

- hosts: localhost


  tasks:
      - ec2: ...
      - add_host: ...

It has to be outside the host group as each fork/host has a different copy
of the shared memory.

While this may seem to be somewhat non-intuitive, it also means you don't
have to do "local_action:" all throughout the provisioning play.

However, I'll agree that this is non-obvious, but somewhat of an artifact
of Ansible not intending to be used as a programming language.

A better way to talk to all servers that function is thus:

- hosts: group1
  tasks:
      - ....

Because what happens here is as soon as a host fails, it will be pulled
*OUT* of the group.

Thus "add_host" really only exists to enable the ec2 provisioning need
where you must dynamically (temporarily) add a host to inventory because it
won't show up until the inventory script is run again, and it's just been
created.

Long story short -- don't worry about this too much -- the key concept is
that Ansible removes failed hosts from the rotation, so if you simply talk
to the original group in a future play, or even further down the task list,
Ansible won't talk to failed hosts again.

Most signs of confusion in using Ansible stem from trying to use it *too*
programmatically, where it's intended to be a lot more direct.

So, basically take out the "add_host" magic (which is there to only support
the provisioning cases) and it will be a lot more straightforward.




On Mon, Mar 24, 2014 at 1:00 AM, Juergen Brendel <[email protected]> wrote:

>
> Hello!
>
> I'm deploying a cluster of app-servers behind a load balancer. When an
> appserver has been installed - and has passed some basic tests - I would
> like to add it to a dynamic group. Later, in the nginx (the load balancer)
> config file template, I'm iterating over this dynamic group in order to add
> only functioning app-servers to the nginx load balancing configuration.
>
> So, in the playbook, which sets up the app-server, I have this here at the
> end:
>
> - name: add new instance to functioning applayer group
>   local_action:
>       add_host name={{ inventory_hostname }}
> groupname=functioning-applayer-hosts
>
> However, only one of my app servers is added to this group. In fact, when
> I watch Ansible process my playbooks, it just looks like this:
>
> ...
>
> TASK: [appserver | running unit tests]
> ****************************************
> skipping: [54.206.225.114]
> skipping: [54.206.165.147]
>
> TASK: [appserver | add new instance to functioning applayer group]
> ************
> ok: [54.206.165.147]        <====== ONLY DONE FOR A SINGLE HOST, FOR SOME
> REASON...
>
> TASK: [appserver | stopping django server]
> ************************************
> changed: [54.206.165.147]
> changed: [54.206.225.114]
>
> TASK: [appserver | starting django server]
> ************************************
> <job 82131229693> finished on 54.206.165.147
> <job 82131229693> finished on 54.206.225.114
> ...
>
> You can see that my unit tests are run on both app-servers, the Django
> process is restarted on both app-servers, but right in the middle only one
> of them is added to the "functioning-applayer-hosts" group.
>
> Any idea why this is the case and how I could fix this?
>
> Thank you very much...
>
> Juergen
>
>
>
>  --
> 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/f6b63fef-a444-4c9d-a6f4-23846f9e7b5b%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/f6b63fef-a444-4c9d-a6f4-23846f9e7b5b%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/CAEVJ8QOX-UJ24VzppHq%3DLMBxycP8RgQFSnxgGPitad_BpeZ%3DmQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to