salt icon indicating copy to clipboard operation
salt copied to clipboard

Feature Request: "with_items" option for file.managed

Open alienzrcoming opened this issue 12 years ago • 5 comments

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

alienzrcoming avatar Dec 31 '13 21:12 alienzrcoming

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.

basepi avatar Jan 03 '14 23:01 basepi

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 avatar Nov 26 '14 09:11 FractalizeR

@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 avatar Dec 01 '14 20:12 basepi

@basepi Thanks a lot! I will definitely check them!

FractalizeR avatar Dec 02 '14 07:12 FractalizeR

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.

stale[bot] avatar Sep 21 '17 21:09 stale[bot]