In below usecase it is not working:
run.yml
----------
---
- hosts: all
connection: local
gather_facts: no
tasks:
- name: include role task
include_role:
name: role1
tasks_from: hello
- hosts: all
connection: local
gather_facts: no
tasks:
- name: include role task
include_role:
name: role1
tasks_from: bye
then inside role tasks:
------------------------
hello.yml
- name: add host
add_host:
name: 'test'
groups: all
- name: refresh
meta: refresh_inventory
and other task file
bye.yml
- name: print
debug:
msg: "bye"
On running
ansible-playbook -i hosts run.yml
PLAY [all]
************************************************************************************************************************
TASK [include role task]
**********************************************************************************************************
TASK [role1 : add host]
***********************************************************************************************************
changed: [localhost]
PLAY [all]
************************************************************************************************************************
TASK [include role task]
**********************************************************************************************************
TASK [role1 : print]
**************************************************************************************************************
ok: [localhost] => {
"msg": "bye"
}
PLAY RECAP
************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
skipped=0 rescued=0 ignored=0
other play is called only on 1 host than new one added.
Regards,
Punit
On Wed, 22 Jan 2020 at 21:45, Vladimir Botka <[email protected]> wrote:
> On Wed, 22 Jan 2020 21:32:54 +0530
> Punit Jain <[email protected]> wrote:
>
> > - hosts: all
> > connection: local
> > gather_facts: no
> >
> > tasks:
> > - name: add host
> > add_host:
> > name: 'testserver'
> > groups: all
> >
> > - name: refresh
> > meta: refresh_inventory
> >
> > - name: print
> > debug:
> > msg: "hello"
> > [...]
> > it doesnot run task for added host
> > I dont see task for testserver.
>
> Split the playbook to 2 plays. Add the host in the first play, and use it
> the
> second.
>
> - hosts: all
> connection: local
> gather_facts: no
> tasks:
> - name: add host
> add_host:
> name: 'testserver'
> groups: all
> run_once: true
>
> - hosts: all
> connection: local
> gather_facts: no
> tasks:
> - name: print
> debug:
> msg: "hello"
>
> HTH,
>
> -vlado
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAFXWBQ%2BcTbMr-muO0hK8tgHkd%2BRJoEVy5WUb_2SG0vne1r0Kyg%40mail.gmail.com.