Feature Request: "with_items" option for file.managed
Hi!
Ansible has a "with_items" option that is useful when managing multiple managed files.
An example:
- name: Set up log rotation for Nginx and Passenger
copy: src={{ item }}-logrotate
dest=/etc/logrotate.d/{{ item }}
with_items:
- nginx
- passenger
With Salt's file.managed, a way to accomplish this is with a jinja loop:
{% for rotate_target in 'nginx', 'passenger' %}
Set up log rotation for Nginx and Passenger:
file.managed:
- name: /etc/logrotate.d/{{ rotate_target }}
- source: salt://nginx-passenger/{{ rotate_target }}-logrotate
{% endfor %}
Alternatively, this could be accomplished in Salt could be a 'with_items' option like so:
Set up log rotation for Nginx and Passenger:
file.managed:
- name: /etc/logrotate.d/{{ item }}
- source: salt://nginx-passenger/{{ item }}-logrotate
- with_items:
- nginx
- passenger
Cheers
This would be useful, though I think we would have to modify the syntax a little. Because {{ item }} is jinja syntax, the jinja renderer would likely complain.
It would be a great addition to Solt system since installing a lot of packages with a separate calls to yum or apt is such a time-waster....
@FractalizeR The pkg calls actually already have great optimization options. For example, you can use the pkgs argument to a pkg.installed call and it will install all of the listed packages in one call. Additionally, in 2014.7.0, we added the mod_aggregate feature which allows us to dynamically combine pkg states into a single call. Check out the release notes on this feature here.
@basepi Thanks a lot! I will definitely check them!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.