SaltStack states pattern and replace for multiple files under directory and for multiple line matches I am using saltstack state pattern and replace to match a pattern and replace with a new pattern. My init.sls file executes below:

`modify_script.sh:
   file.replace:
      - name: /path/to/script.sh
      - pattern: /aaa/bbb
      - repl: /aaa/ccc
      - pattern: /xxx/yyy
      - repl: /xxx/zzz`


The above works good if I use a single pattern and replace. This fails for multiple patterns and replaces as shown above. How to achieve multiple pattern replace for two or more patterns in a single file?

Secondly, I have multiple files in a directory which requires a pattern match and replace. 

modify_script.sh:
       file.replace:
          - name: /path/to/dir [having multiple files which require update]
          - pattern: /aaa/bbb
          - repl: /aaa/ccc

Can I match the patterns for all the files under directory? I wouldn't want to match and replace a single file individually. 
Please advise.
You should use Jinja to loop over a list of files and pattern/replacement pairs.

{% set files = ['/a/foo.sh', '/b/bar.sh', '/b/baz.sh'] %}

{% for file in files %}
{% for p, r in [('/aaa/bbb', '/aaa/ccc'), ('/xxx/yyy', '/xxx/zzz')] %}
replace {{ p }} in {{ file }}:
   file.replace:
      - name: {{ file }}
      - pattern: {{ p }}
      - repl: {{ r }}
{% endfor %}
{% endfor %}


Keep in mind the identifiers need to be unique, that's why variables in replace {{ p }} in {{ file }}: are used.