Search code examples
yamlsalt-project

SaltStack: edit yaml file on minion host based on salt pillar data


Say the minion host has a default yaml configuration named myconf.yaml. What I want to do is to edit parts of those yaml entries using values from a pillar. I can't even begin to think how to do this on Salt. The only think I can think of is to run a custom python script on the host via cmd.run and feed it with input via arguments, but this seems overcomplicated.

I want to avoid file.managed. I cannot use a template, since the .yaml file is big, and can change by external means. I just want to edit a few parameters in it. I suppose a python script could do it but I thought salt could do it without writing s/w

I have found salt.states.file.serialize with the merge_if_exists option, I will try this and report.


Solution

  • This can be done for both json and yaml with file.serialize. Input can be inline on the state or come from a pillar. A short excerpt follows:

    state:

    cassandra_yaml:
      file:
        - serialize
    #    - dataset:
    #        concurrent_reads: 8
        - dataset_pillar: cassandra_yaml
        - name: /etc/cassandra/conf/cassandra.yaml
        - formatter: yaml
        - merge_if_exists: True
        - require:
          - pkg: cassandra-pkgs
    

    pillar:

    cassandra_yaml:
      concurrent_reads: "8"