FAQ
Hello fellow salt users,

I have an application that is configurated by yaml, well salt pillar
data is yaml, how can I quickly generate a yaml file from the pillar
data to a configuration file.
Basically this.
pillar/myapp.sls

myapp:
   option1:
    - looolol
    - lololol2

And a state with something like.
/etc/myapp/config
   file:
     - managed
     - source???

Any ideas ?

--
Regards,
Alfredo Palhares

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Seth House at Jul 2, 2014 at 7:00 pm

    On Wed, Jul 2, 2014 at 12:00 PM, Alfredo Palhares wrote:
    I have an application that is configurated by yaml, well salt pillar
    data is yaml, how can I quickly generate a yaml file from the pillar
    data to a configuration file.
    Take a look at the yaml() Jinja filter. Just keep in mind the nested
    templating that's going on here. If you're using any multi-line
    strings or multi-line (pretty) YAML it's easy to mess up the
    indentation.

    http://docs.saltstack.com/en/latest/ref/renderers/all/salt.renderers.jinja.html#salt.utils.jinja.SerializerExtension

    Something like this should be pretty safe:

    /etc/myapp/config
       file:
         - managed
         - contents: |
             {{ salt['pillar.get']('myapp') | yaml() | indent(8) }}

    The flow_control parameter to output pretty YAML is new in the
    upcoming Salt feature release (Helium). In the 2014.1 release the YAML
    will be output on a single line, I think.

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alfredo Palhares at Jul 7, 2014 at 2:42 pm
    Hello,

    First of all thanks for your input.
    /etc/myapp/config
    file:
    - managed
    - contents: |
    {{ salt['pillar.get']('myapp') | yaml() | indent(8) }}
    The yaml() method seems to be ignored, the template just gets the pillar
    data as a python dictionary.

    Do I need to enable the serializer extension[1] in some way ? I am using
    salt 2014.1.5

    [1] https://sourcegraph.com/github.com/saltstack/salt/symbols/python/salt/utils/jinja/SerializerExtension


    --
    Regards,
    Alfredo Palhares

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Seth House at Jul 8, 2014 at 6:53 am

    On Mon, Jul 7, 2014 at 7:42 AM, Alfredo Palhares wrote:
    Do I need to enable the serializer extension[1] in some way?
    No, it's on by default and it's been in Salt for two major releases
    now. I can't think of a reason it wouldn't work in the above example.
    Does the ``json()`` filter produce JSON?

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alfredo Palhares at Jul 8, 2014 at 9:56 am
    Hello Seth,
    No, it's on by default and it's been in Salt for two major releases
    now. I can't think of a reason it wouldn't work in the above example.
    Ok, Is there any way i can prove its really there ?

    Does the ``json()`` filter produce JSON?
    No, Doing:
      - contents: {{ pillar["myapp"]["mydata"] | json() }}

    Still produces a ordered dictonary on the template.
    Any susgestions ?

    --
    Regards,
    Alfredo Palhares

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Seth House at Jul 10, 2014 at 12:55 am

    On Tue, Jul 8, 2014 at 2:56 AM, Alfredo Palhares wrote:
    Ok, Is there any way i can prove its really there ?
    What is output when running this state?

    http://paste.fedoraproject.org/116836/04953642/

    (Formatting of inline version below may be wrong.)

    test_if_has_yaml_filter:
       cmd:
         - run
         - name: |
             echo 'The statement "I can see the YAML filter," is {{ yaml is
    callable }}'.

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Seth House at Jul 10, 2014 at 1:16 am
    I ran a quick test on v2014.1.5. Below are the files & output:

    http://paste.fedoraproject.org/116837/54858140/

    I'm can't think of a reason the OrderedDict would be showing through
    in your template. Could you pastebin what you're seeing?

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alfredo Palhares at Jul 10, 2014 at 2:18 pm
    Hello Seth,

    I ran your statement, even without a succesful run, the {{ yaml is
    caoable }} return true[1]

    The the rendering still does not work. I am really out of opinions :(

    [1] http://pastie.org/private/ij41bgiqwsvewgfdp0og


    Thank you so much for your help so far!

    --
    Regards,
    Alfredo Palhares

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alfredo Palhares at Jul 10, 2014 at 2:28 pm
    While being true, here is an echo "{{ pillar["myapp"] | yaml() }}"
    command[1]
    The renderer is there, maybe the syntax is wrong?

    [1] http://pastie.org/private/puykt9au4lkd0s1lhe4giq


    --
    Regards,
    Alfredo Palhares

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Seth House at Jul 11, 2014 at 12:41 am

    On Thu, Jul 10, 2014 at 7:28 AM, Alfredo Palhares wrote:
    While being true, here is an echo "{{ pillar["myapp"] | yaml() }}"
    command[1]
    The renderer is there, maybe the syntax is wrong?
    It looks like there may be a rogue newline in the Pillar contents
    somewhere that is messing things up when it's inserted into the state.
    Try using a multi-line YAML string and the Jinja intent filter:

    your_state:
       cmd:
         - run
         - name: |
             echo "{{ pillar["myapp"] | yaml() | indent(8) }}"

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Daniel Jagszent at Jul 10, 2014 at 6:02 pm
    Hi Alfredo ,

    I think you have to add quotes:

    - contents: '{{ pillar["myapp"]["mydata"] | json() }}'


    Anyways, if I find myself juggling around Jinja filters just to produce
    valid YAML, I mostly opt for writing that particular state in pydsl instead.
    http://docs.saltstack.com/en/latest/ref/renderers/all/salt.renderers.pydsl.html

    #!pydsl

    import json

    state('/my/file/name').file.managed(
       contents=json.dumps(__pillar__["myapp"]["mydata"])
    )


    Alfredo Palhares wrote:
    Hello Seth,
    No, it's on by default and it's been in Salt for two major releases
    now. I can't think of a reason it wouldn't work in the above example.
    Ok, Is there any way i can prove its really there ?

    Does the ``json()`` filter produce JSON?
    No, Doing:
    - contents: {{ pillar["myapp"]["mydata"] | json() }}

    Still produces a ordered dictonary on the template.
    Any susgestions ?

    --
    Regards,
    Alfredo Palhares
  • Alfredo Palhares at Jul 11, 2014 at 12:00 pm
    Hello Daniel,
    Hi Alfredo ,

    I think you have to add quotes:

    - contents: '{{ pillar["myapp"]["mydata"] | json() }}'


    Anyways, if I find myself juggling around Jinja filters just to produce
    valid YAML, I mostly opt for writing that particular state in pydsl instead.
    http://docs.saltstack.com/en/latest/ref/renderers/all/salt.renderers.pydsl.html

    #!pydsl

    import json

    state('/my/file/name').file.managed(
    contents=json.dumps(__pillar__["myapp"]["mydata"])
    )
    Actually its YAML, but I tried that renderer, just to see it happening.

    But I was greeted by this error.

    [1] http://pastie.org/private/xadwa5jwsibnrv1hggclq


    --
    Regards,
    Alfredo Palhares

    --
    You received this message because you are subscribed to the Google Groups "Salt-users" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Daniel Jagszent at Jul 11, 2014 at 12:30 pm
    Hi Alfredo,

    please read http://docs.saltstack.com/en/latest/ref/renderers/index.html .

    The shebang "#!pydsl" is important.

    ------ 8< ------
    #!pydsl

    import yaml

    state('/etc/salt/cloud.yaml').file.managed(contents=yaml.dump(__pillar__["salt"]["cloud"]))

    ------ >8 ------

    Alfredo Palhares wrote:
    Hello Daniel,
    Hi Alfredo ,

    I think you have to add quotes:

    - contents: '{{ pillar["myapp"]["mydata"] | json() }}'


    Anyways, if I find myself juggling around Jinja filters just to produce
    valid YAML, I mostly opt for writing that particular state in pydsl instead.
    http://docs.saltstack.com/en/latest/ref/renderers/all/salt.renderers.pydsl.html

    #!pydsl

    import json

    state('/my/file/name').file.managed(
    contents=json.dumps(__pillar__["myapp"]["mydata"])
    )
    Actually its YAML, but I tried that renderer, just to see it happening.

    But I was greeted by this error.

    [1] http://pastie.org/private/xadwa5jwsibnrv1hggclq


    --
    Regards,
    Alfredo Palhares

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupsalt-users @
postedJul 2, '14 at 6:00p
activeJul 11, '14 at 12:30p
posts13
users3

People

Translate

site design / logo © 2022 Grokbase