Tested this some more, and it seems to actually do what I expected. The 
include is run on both hosts once, sequentially. It seems a little weird 
that Ansible is showing the host as host1 -> None instead of host1 -> host1 
or host1 -> host2 for the debug tasks, but that's only a minor problem. I'm 
wondering if that's a bug or me doing something wrong. I tried replacing 
the role code with just a debug delegated to 127.0.0.1, and it's still 
showing host1 -> None.

On Friday, October 14, 2016 at 10:20:21 PM UTC+2, Stig Døssing wrote:
>
> I'm trying to use the approach described here 
> https://github.com/ansible/ansible/issues/12170 to get part of a role to 
> run serially. I am on 2.1.2.0, but have also tried 2.1.1.0 and 2.0.2.0.
>
> - include: do_deploy.yml
>   with_items: "{{ play_hosts }}"
>   delegate_to: "{{ item }}"
>   run_once: true
>
>
> do_deploy.yml simply contains
>
> - debug: msg="{{ item }}"
>
> The role is being run from a playbook where hosts contains two hosts. I'd 
> like this code to include do_deploy.yml once per host, and delegate each 
> include to the host it's currently iterating over.
>
> I'm seeing this
>
> TASK [deploy : include] 
> *******************************************************
> included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host1
> included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host1
>
> TASK [deploy : debug] 
> *********************************************************
> ok: [host1 -> None] => {
>     "msg": "host1"                                                       
>                  
> }                                                                         
>                    
>
> TASK [deploy : debug] 
> *********************************************************
> ok: [host1 -> None] => {
>     "msg": "host2"                                                       
>                  
> }    
>
>
> while I'd expect to see this
>
> TASK [deploy : include] 
> *******************************************************
> included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host1
> included: /home/stig/ansible/roles/deploy/tasks/do_deploy.yml for host2
>
> TASK [deploy : debug] 
> *********************************************************
> ok: [host1 -> None] => {
>     "msg": "host1"                                                       
>                  
> }                                                                         
>                    
>
> TASK [deploy : debug] 
> *********************************************************
> ok: [host2 -> None] => {
>     "msg": "host2"                                                       
>                  
> }   
>
> Basically run_once seems to be acting like delegate_to isn't being used.
>
> Am I misusing delegate_to, or is there some other way to fake serial: 1 
> for an include?
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/bdd868aa-1547-4aa2-b1bf-872aa9909b85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to