Ansible 1.3 - cached facts.

Hi,

Reading change log for Ansible, since version 1.3 there is some improvment with facts - they can be cached. Is this right?
Is yes - can I have some examples of this please (links, git, website, ansible-example :)).

My challange is that we have quite a lot hosts in cloud service, and we’re adding new hosts quite often (now is about 200 hosts already). Our ansible play is configured to configure hosts and add them to monitoring system.
I would like to be able to do:

  • create new hosts
  • Add this hosts to ansible and run all ansible plays only on these new hosts
  • Run ansible play to configure monitoring system to add all new hosts - and use facts from previous hosts. We’re using template for nagios to get default_ips from all hosts to generate valid hosts.

Without this solution now I need 1 hour to add a few nodes to monitoring system. Ansible must run all tasks on all hosts and then generate configuration files based on gathered facts.

Could you point me to some direction whether is this possible, or not - I am happy to using ansible 1.3.

Thank you very much for any help.

Best regards,
Marcin Praczko.

Fact caching is not yet available in Ansible, in the essense that if you don’t gather facts in the current playbook execution, they do not yet persist.

Something that we’re looking at doing for a future release.

Now why your process takes an hour, I’m extremely super greatly confused by :slight_smile:

Hi Michael,

This is quite suprised - I thought that is already done in 1.3 - but maybe I red something wrong and ‘jump too much in future’ :slight_smile:

In general, ansbile is doing great job for us.

  • We are creating empty nodes in cloud - with really, really basic configuration to allow us get access over SSH and setup them. (This is done by our own scripts - not ansible).
  • Next step is run ansbile to configure all these nodes for our standards. And this includes, install all required packages on nodes, configure them, run them, and then add these nodes to monitoring system (nagios / munin, etc).
    This process in general is long - even for few nodes. Which is OK. But now ansible must connect with 200 nodes and check whether task is done (for exmaple install nagios-plugins) and this task should be done ony on new nodes. Time increases beacuse every task must be also run on all ‘already configured’ node. And on new nodes task will be done.

So in general everything is working well, but so far I don’t know any solution how to make ansible run only on new nodes which must be configured - not touching others, and gather details from all of them for monitoring configuration.
If there are any 'trick’s like - connect with node, check something and then skipp all roles - that would be great.

Hope that helps.

I look forward for this option related with cached facts.

Best regards,
Marcin Praczko

There’s presently no “skip” task to skip the rest of the play.

It’s been discussed theoretically once or twice and I think would be of value.

BTW, forgot to share

  • shell: /usr/bin/foo
    register: foo

  • group_by: key=some_variable_{{ foo.stdout }}

If you wanted to select just the hosts in a play where foo returned “xyz” you can do in a following play

hosts: some_variable_xyz

This effectively can give you skip behavior.

Have a small play that talks to all hosts and does the tests, then a play after that applies roles to those that pass the test.

Hi Michael.

I think this is exectly what I am looking for. I need do small test and implement this.

Play #1 - tests + groups
Play #2 - Restrict to hosts created on group_by in Play #1
Play #3 - Genereate configuration files for monitoring (Gathered on Play #1).

If all tasks must be run on all nodes - is enough just change Play #2 hosts lists (small effort, quick fix).

Thank you for help.
Will test this and give some feedback once is done.

Best regards,
Marcin Praczko

As a reference:

     https://github.com/ansible/ansible/issues/1476