ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
62.53k stars 23.85k forks source link

make with_ loops configurable #12086

Closed bcoca closed 5 years ago

bcoca commented 9 years ago
ISSUE TYPE

Feature Idea

COMPONENT NAME

core

ANSIBLE VERSION

2.1

CONFIGURATION
OS / ENVIRONMENT
SUMMARY
how: 
    forks: 1
    pause: 0
    squash: name
    label: "{{item.name}}"
    end: on_fail
with_items: ...

docs to current state at:

http://docs.ansible.com/ansible/playbooks_loops.html#loop-control

STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
amenonsen commented 9 years ago

Please let's not call it how. That's even worse to read than become: true. But the functionality under it looks great.

bcoca commented 9 years ago

includes fix for #10695

mahemoff commented 8 years ago

Excellent. In the interests of bikeshedding, maybe call it looping:.

realcnbs commented 8 years ago

:+1:

yikaus commented 8 years ago

+1

jyennaco commented 8 years ago

+1 especially for within host parallelization!

rbarabas commented 8 years ago

:+1:

hloeffler commented 8 years ago

:+1: but lets not call it "how"

bcoca commented 8 years ago

so here is a workaround for breaking a loop task after the first failure

- hosts: localhost
  vars:
    myvar:
        - 1
        - 2
        - 3
        - 4
        - 5
  tasks:
    - name: break loop after 3
      debug: msg={{item}}
      failed_when: item == 3
      register: myresults
      when: not (myresults|default({}))|failed
      with_items: "{{myvar}}"
yikaus commented 8 years ago

@bcoca not working from end (ansible 1.9.3 ubuntu )

TASK: [break loop after 3] **** ok: [localhost] => (item=1) => { "failed": false, "failed_when_result": false, "item": 1, "msg": "1" } ok: [localhost] => (item=2) => { "failed": false, "failed_when_result": false, "item": 2, "msg": "2" } failed: [localhost] => (item=3) => {"failed": true, "failed_when_result": true, "item": 3, "verbose_always": true} msg: 3 ok: [localhost] => (item=4) => { "failed": false, "failed_when_result": false, "item": 4, "msg": "4" } ok: [localhost] => (item=5) => { "failed": false, "failed_when_result": false, "item": 5, "msg": "5" }

bcoca commented 8 years ago

ah, yes, it will work as is in 2.0 as in 1.9 the registration does not occur until after the loop is done.

mattyb commented 8 years ago

+1 on forks

t1m0thy commented 8 years ago

+1 perhaps instead of "how", loop_details or options?

daniel-sc commented 8 years ago

+1

senderista commented 8 years ago

+1, using wait_for from localhost to wait for 100 EC2 hosts to come up is killing me...

beholt commented 8 years ago

+1 for similar reason to senderista

ykuksenko commented 8 years ago

+1

evenme commented 8 years ago

:+1:

kustodian commented 8 years ago

Both squash and forks would be awesome features which would speed up Ansible execution immensely.

I would also replace how with something like loop_details, loop_settings, loop_options, or anything similar.

bcoca commented 8 years ago

loop_control , already in 2.1 with the label part implemented.

squash might just go away as it is easy to just pass a list to the modules that support it:

apt: name={{listofpackages}}

and avoid the loop completely

mahemoff commented 8 years ago

http://docs.ansible.com/ansible/playbooks_loops.html#loop-control

jeanpaulmanjarres-payulatam commented 8 years ago

+1 forks

ansafonov commented 7 years ago

+1 forks

resmo commented 7 years ago

I had a use case for a new config for a conditional break break_when

kasabov commented 7 years ago

+1 forks and I hope it'll also work for parallelizing sequences of tasks to run as in: - include: service.yml with_items: "{{services|default([])}}"

Otherwise, there's the async/async_status already.

bryfry commented 7 years ago

+1 forks

Me waiting for openstack modules to iterate through with_ loops on 100+ items... image

ghjm commented 7 years ago

+1 on forks. Could use this for copying AMIs to all the AWS regions.

aarlint commented 7 years ago

+1 on forks. Please! make it part of loop_control

uebertrieben commented 7 years ago

+1 on forks

ghost commented 7 years ago

+1 on forks

Schroeffu commented 7 years ago

+1, need forks too :-)

Haxe18 commented 7 years ago

+1 on forks

pschorf commented 7 years ago

+1 on forks

berendt commented 7 years ago

Forks would be awesome, +1

xenithorb commented 7 years ago

I always sit in silence not wanting to contribute to the spam, because it's hard to gauge between projects whether it's welcomed or not, but it looks like the fork +1 train has left the station!

+1 on forks

adrien-mogenet commented 7 years ago

+1 on forks

ImpSy commented 7 years ago

+1 on forks

hai-ld commented 7 years ago

:+1: on forks

ansibot commented 7 years ago

@bcoca Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

Please set the description of this issue with this template: https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

d3matt commented 7 years ago

+1 on forks

inponomarev commented 7 years ago

+1 on forks!

ahharu commented 7 years ago

+1 on Forks!

bluefish6 commented 7 years ago

+1 on forks!

jt1 commented 7 years ago

+1 on forks!

bitliner commented 7 years ago

Any update on fork? When is it supposed to be ready? My use case is instantiating about 20 containers on a server with with_sequence. Now it takes too many ages :( I would be glad to help, but I would need some tips on where to put hands

bcoca commented 7 years ago

@bitliner no one has created a PR for it, if that is what you are asking, its actually very hard to do correctly.

as for your issue, just declare X hosts in inventory and loop over hosts: instead of with_ to create them in paralell.

inventory:

[containers]
container[000:020]
hosts: containers
gather_facts: false
tasks:
   - container: state=present name={{inventory_hostname}}

i.e container is a 'made up' module.

bitliner commented 7 years ago

@bcoca your solution is not clear to me. To be sure, is this what you mean?

hosts file

[containers]
192.168.1.100
192.168.1.100
192.168.1.100
192.168.1.100
... and so on based on the degree of parallelism I want to get ...

main.yml file

hosts: containers
gather_facts: false
tasks:
   - container: state=present name={{inventory_hostname}}

based on a container module that I should implement, correct? In this case, I would have all containers with the same name, and that is not acceptable, correct?

Furthermore, what are the challenges to do implement loop in parallel correctly?

My use case needs to speed up this task:

- name: "Start clients"
  docker_container:
    name: "mycontainer-{{ item }}"
    image: myimage
    links: 
      - server-{{item}}:server-{{item}}
  with_sequence: count={{ scale }}

I can't use docker-compose scale because I need to route traffic among containers in a specific way (that is why I use with_sequence to generate different docker container names).

I could build a module that takes the declaration of a container and based on a scale parameter it instantiates remotely multiple containers in parallel. Does it make sense? Do you have any help to understand how to call/re-use in myModule the docker_container module and what are the API that Ansible offers to run something in parallel?

bcoca commented 7 years ago

@bitliner you did not follow my instructions, i had unique names in inventory (using range to work just like a sequence). As names are unique in inventory, you just declared the same name N times, but still have one host, which does not cause your 2nd issue on dupe names of containers as you only loop over 1 host.

In any case, if you want to follow up with your issue, use ML or IRC as it would be a bit off topic for this ticket.

bitliner commented 7 years ago

@bcoca How can I have one host if you declared 20 hosts?

[containers]
container[000:020]

is going to connect to container001, container002, etc.

It works for having unique names, but what is not clear to me is why you say I still have one host (instead of 20). hosts:containers means to me 20 hosts, not just one. What am I ignoring in this solution?

bcoca commented 7 years ago

@bitliner cause this:

[containers]
192.168.1.100
192.168.1.100
192.168.1.100
192.168.1.100

is not 4 hosts, but 1

also at this point this is pretty much off topic, if you want to continue getting help on this go to IRC or ML