{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/10695","labels_url":"https://api.github.com/repos/ansible/ansible/issues/10695/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/10695/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/10695/events","html_url":"https://github.com/ansible/ansible/issues/10695","id":68207574,"number":10695,"title":"Feature idea: within-host parallelization for with_items loops","user":{"login":"wincent","id":7074,"avatar_url":"https://avatars.githubusercontent.com/u/7074?v=3","gravatar_id":"","url":"https://api.github.com/users/wincent","html_url":"https://github.com/wincent","followers_url":"https://api.github.com/users/wincent/followers","following_url":"https://api.github.com/users/wincent/following{/other_user}","gists_url":"https://api.github.com/users/wincent/gists{/gist_id}","starred_url":"https://api.github.com/users/wincent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wincent/subscriptions","organizations_url":"https://api.github.com/users/wincent/orgs","repos_url":"https://api.github.com/users/wincent/repos","events_url":"https://api.github.com/users/wincent/events{/privacy}","received_events_url":"https://api.github.com/users/wincent/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/feature_idea","name":"feature_idea","color":"006b75"},{"url":"https://api.github.com/repos/ansible/ansible/labels/P3","name":"P3","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-04-13T22:24:36Z","updated_at":"2015-07-09T17:32:50Z","closed_at":null,"body":"This has come up before (for example, see [this mailing list thread](https://groups.google.com/forum/#!topic/ansible-devel/lhvukkszKUA)), but the basic idea is that you may want to run a large number of `command` module operations on a single host in parallel via `with_items` if they don't have any dependencies on one another.\r\n\r\nIn that thread, the specific example is a 10-host inventory, but with about 500 commands to run on each host, each command taking 2 seconds.\r\n\r\nIt seems that Ansible has multi-host parallelism baked into it deeply, but doing any kind of within-host parallelism requires some hackery. For example, you can trick Ansible into using it's multi-host parallelism by creating fake inventory entries and having a play that targets those \"hosts\", which are really all just aliases of the same machine ([as suggested here](https://groups.google.com/d/msg/ansible-project/8Yh4jy68Kmk/GJC2y44XjNAJ)). Depending on the complexity of your playbook, this might get complicated to do, and it obfuscates what's really going on for people reading the playbook.\r\n\r\nAnother thing you can do is to run a script that has some parallelism internally (for example, you can template out a script that forks and runs multiple commands) but then you lose some of the nice things that Ansible gives you around change-detection and reporting.\r\n\r\nSo, the idea here is effectively to add some kind of option to Ansible to signal that it should try running multiple entries from a `with_items` list in parallel (probably a number indicating the desired level maximum of concurrent tasks) when connecting to a particular host. I can see this as being most useful with the `command` module (or perhaps the `shell` module), but there may be other use cases as well."},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/120080743","html_url":"https://github.com/ansible/ansible/issues/10695#issuecomment-120080743","issue_url":"https://api.github.com/repos/ansible/ansible/issues/10695","id":120080743,"user":{"login":"nicocesar","id":425081,"avatar_url":"https://avatars.githubusercontent.com/u/425081?v=3","gravatar_id":"","url":"https://api.github.com/users/nicocesar","html_url":"https://github.com/nicocesar","followers_url":"https://api.github.com/users/nicocesar/followers","following_url":"https://api.github.com/users/nicocesar/following{/other_user}","gists_url":"https://api.github.com/users/nicocesar/gists{/gist_id}","starred_url":"https://api.github.com/users/nicocesar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicocesar/subscriptions","organizations_url":"https://api.github.com/users/nicocesar/orgs","repos_url":"https://api.github.com/users/nicocesar/repos","events_url":"https://api.github.com/users/nicocesar/events{/privacy}","received_events_url":"https://api.github.com/users/nicocesar/received_events","type":"User","site_admin":false},"created_at":"2015-07-09T17:32:50Z","updated_at":"2015-07-09T17:32:50Z","body":"+1 my usecase involves creating tens of firewalling rules with gce_net module. they can all be done in parallel.  I'm  using `with_items` too "}}