ansible-playbook --limit limitations?

Hi,

I've got a fairly complex playbook which uses Ansibles
orchestration features
(i.e. "for n in groups['some group'] ....") and a big enough stack
that I'd like to pass '--limit' to my plays as we build out configs etc.

An example: several servers lookup members of the 'zookeepers'
group to generate their config files
(this is just one example; different hosts have different dependencies).

So if i try

ansible-playbook -i inventory site.yml --limit nonzkhost

the run fails with:

fatal: [nonzkhost1] => {'msg': "One or more undefined variables: 'dict
object' has no attribute 'ansible_eth1'", 'failed': True}

To use the '--limit' flag, I have to remember to also list all
zookeepers in a play.
Similar issues happen with Ansibles 'retry' feature.

I think my issue is that I need actual facts gathered from those hosts
rather than just their names (which are accessible in the inventory of course).

Is there a flag I can pass to get a full 'GATHER FACTS' pass before
only running a play against selected nodes, or am I just Doing It Wrong here?

If you use limit it won’t gather facts from machines not in the limit group.

(There have been a few threads about this)

Thanks Michael

Yeah so it seems - is that by design?

This can actually be dangerous (if for example all zookeepers aren't
explicitly specified, configurations will drop some from the client configs
and bounce services, potentially leading to cluster splits),
would be good if there was some workaround.

Is there any way to make orchestration and limit play nicely together,
or do you feel they're mutually exclusive?

there are other ways to do this, but not with --limit

  • hosts: all
    name: this just gathers facts

  • hosts: “some_group{{limit|default(‘’)}}”

This.

I know I'm new here, but this has bitten me several times already. It
seems that fact gathering of other hosts not in the play loop is such
a common thing that there should be a more explicit way to do this
besides just the side effect of a play with no tasks. Because you have
to set things up to always have to pass an extra variable on the
command line which increases the amount you need to memorize just to
execute every play. And then if things change such that you need to
include other groups in the task gathering that are not included in
the execution you have to retrain everyone for every invocation that
isn't global.

I appreciate that there is a work around for the general case, but
fact gathering of other hosts seems like such a common thing that
there should be a way to do it not as a side effect that needs
invocation hurdles.

Just my 2¢

It’s a popular request.

We’re aware of it - but also chasing about 500 other things people want and have to balance these things :slight_smile:

Stay tuned!