using file.manage and file.blockreplace in seperate sls on the same file

175 views
Skip to first unread message

Paul Mulvihill

unread,
Nov 23, 2016, 7:58:13 AM11/23/16
to Salt-users
Hi everyone..

I'm creating a state to install some software. I have the package state to install a config file (from template). that part works fine.
What I want to do is then use a seperate state file (a role) that then adds extra content to that config file (mainly extra content for HA setup).

In the core state i have the file.managed code
/etc/st2/st2.conf:
  file.managed:
    - source: salt://{{ tpldir }}/files/st2.conf.sls
    - template: jinja
    - require:
      - pkg: st2

and then in the role state i call the core state and then have a file.blockreplace.
st2_ha_controller:
  file.blockreplace:
    - name: /etc/st2/st2.conf
    - source: salt://{{ tpldir }}/files/st2_ha_controller.sls
    - template: 'jinja'
    - append_if_not_found: True
    - require_in:
      - file: /etc/st2/st2.conf


However when I run role. it just flits between adding and removing the extra lines I want the role to add to the config file.
Is there a way to link the two actions together, while keeping them in seperate files, so with each run the role it doesn't just bounce between removing and adding the lines in the st2_ha_controller template file?

I could use pillar data but want to know if there is a way to do this using my roles setup as that is easier to manage from my setup.

salt master: 2015.8.8-2
minions will be the same or higher.

Any suggestions?


thanks

Paul

Paul Mulvihill

unread,
Nov 24, 2016, 10:35:40 AM11/24/16
to Salt-users
Found the following which did the trick for me.

https://docs.saltstack.com/en/latest/ref/states/extend.html

but only works because the second sls file includes the first one.
Reply all
Reply to author
Forward
0 new messages