play_hosts

Hi,

I am a n00b and I am trying to create a CA playbook that first locally creates certs, keys etc (using easy-rsa’s pkitool) and then deploys these to the different play_hosts. -I might be going about this the wrong way, but is there a way to register the play_hosts in a list that can then be used when I change play_hosts to be just localhost, and then when I do the deploy go back to the original play_hosts?

`

you already have a play_hosts variable with the ‘current active hosts’ in the play​, but it will be reset every play.

In this case I would just rewrite the play to use:

with_items: groups[‘all’]

​-The problem with ‘with_items: groups[‘all’]’ is that it takes that directly from /etc/ansible/hosts rather than using whatever hosts-pattern that was supplied on the command-line - i.e. ‘–limit ​somehosts’

`

somehosts.yml

What should current_host be replaced with so that the below only runs for the host localhost?

`

when: inventory_hostname == 'localhost’​

" with_items: groups[‘all’]"

I wouldn’t. I’d use the host loop since it’s already there.

  • hosts: all
    tasks:
  • local_action: …