Hi,
i guys, is there a possibility to do stuff like the following?
my playbook:
Hi,
i guys, is there a possibility to do stuff like the following?
my playbook:
Hi,
Take a look at the "add_host" module which could probably be used to
achieve this. Hope this helps!
-Tim
Cool! I didnt find it before… it seems that this module really helps me out
Hi once again,
maybe some can give me one more hint, what my failure here:
Do you have any hosts in [all] right now? You need at least one,
probably "localhost". So I'd try something like this:
inventory:
[local]
localhost
and then the play:
- hosts: local
tasks:
- name: add hosts to new group
action: add_host name=10.1.93.171 groups=just_created
...
Your second play looks fine.
Hope this helps,
-Tim
Yeah be aware hosts:all is not how you want to use “group_by”, more like “hosts:localhost”. Won’t hurt anything, but you really want to only run that step once, not once per host.
And you want to make sure that localhost is defined in inventory too.
Hi Michael, hi Tim,
you’re right, host: all isnt good, but i limited the playbook call to one single host with -l :)… Anyways, yes i got an inventory with one group (all) and about 4000 machines.
The machine in my test play (10.1.93.171), exists also in there.
Now i moved my inventory script in /etc/ansible/hosts and have written only one host (localhost) in there as Tim suggested. same result:
lborchard@smo001:~/ansible_work$ ansible-playbook -l localhost count-tst.yml -vv
PLAY [all] *********************
GATHERING FACTS *********************
REMOTE_MODULE setup
ok: [localhost]
TASK: [add hosts to new group] *********************
creating host via ‘add_host’: hostname=10.1.93.171
added host to group via add_host module: just_created
changed: [localhost] => {“changed”: true, “new_groups”: [“just_created”], “new_host”: “10.1.93.171”}
PLAY [just_created] *********************
skipping: no hosts matched
PLAY RECAP *********************
localhost : ok=2 changed=1 unreachable=0 failed=0
lborchard@smo001:~/ansible_work$ cat /etc/ansible/hosts
[all]
localhost
Dont get it…
lborchard@smo001:~/ansible_work$ ansible --version
ansible 1.1