Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two ssh keys that I'm trying to deploy to one of my minions.But I cant seem to get it to deploy.It errors out....Here is the init.sls in pillars....

   - source: salt://private/id_rsa

 - source: salt://private/

here is my init.sls states.....

    - name: {{pillar['private']}}

...... I must be doing something wrong (obviously)... not sure what.. .any suggestions??

share|improve this question
I'd like to help, but I can't answer with the information provided. Part of the reason is the yaml formatting. Edit your question but leave a blank link above and below each codeblock, then indent each line in the codeblock by at least 4 spaces. Second, did you already succeed in doing this without pillars in the equation? I've never seen pillar data set up they way you have it. – Dan Garthwaite Oct 23 '13 at 18:52
Did you find an answer to your question? – Dan Garthwaite Nov 6 '13 at 23:48
Yes, I believe I did – secure212 Nov 7 '13 at 19:00
up vote 8 down vote accepted

The Salt Pillar system does not have an init.sls file. Both states and pillars has a top.sls file. States that are subdirectories may have an init.sls file.

Step 1: Define your users in /srv/pillar/users.sls


  - name: fred
    fullname: Fred Flintstone
    uid: 4001
    gid: 4001
    shell: /bin/bash
      - bowling
    shadow: $6$Sasdf/Ss$asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfasdfsadfsadfsdf
    authkey: ssh-dss AAAAasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafa =
    sshpub: ssh-dss AAAAasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafa =

  - name: barney
    fullname: Barney Rubble
    uid: 4002
    gid: 4002
    shell: /bin/bash
      - bowling
    shadow: $6$Suiop/Ss$uiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopsadfuiopsadfsadfsdf
    authkey: ssh-dss AAAAuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafa =
    sshpub: ssh-dss AAAAuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafa =

Step 2: Add the new pillar to /srv/pillar/top.sls

    - users

Step 3: Use jinja to map pillar to states in /srv/salt/user/init.sls

{% for user in pillar['users'] %}
    - name: {{}}
    - gid: {{user.gid}}

    - name: {{}}
    - fullname: {{user.fullname}}
    - password: {{user.shadow}}
    - shell: {{}}
    - uid: {{user.uid}}
    - gid: {{user.gid}}
    {% if user.groups %}
    - optional_groups:
      {% for group in user.groups %}
      - {{group}}
      {% endfor %}
    {% endif %}
    - require:
      - group: user_{{}}
    - name: /home/{{}}
    - user: {{}}
    - group: {{}}
    - mode: 0751
    - makedirs: True

    - name: /home/{{}}/.forward
    - text: {{}}

    - name: /home/{{}}/.ssh
    - user: {{}}
    - group: {{}}
    - mode: 0700

{% if 'authkey' in user %}
    - user: {{}}
    - name: {{user.authkey}}
{% endif %}

{% if 'sshpriv' in user %}
    - name: /home/{{}}/.ssh/id_rsa
    - user: {{}}
    - group: {{}}
    - mode: 0600
    - contents_pillar: {{user.sshpriv}}
{% endif %}

{% if 'sshpub' in user %}
    - name: /home/{{}}/.ssh/
    - user: {{}}
    - group: {{}}
    - mode: 0600
    - contents_pillar: {{user.sshpub}}
{% endif %}
{% endfor %} # user in users
# vim: ft=yaml tabstop=2 sts=2 sw=2 et ai si

Don't forget to sync the minions with the new pillars!

salt targetminions saltutil.refresh_pillar
share|improve this answer
I was unable to get this example to work on Salt 2014.7.1; it appears to give an error: "Jinja variable 'str object' has no attribute 'name'" . I have resorted to doing something like this in the user/init.sls: {% for user, data in salt['pillar.get']('users', {}).iteritems() %} This will significantly change the sls file throughout; if I come up with a working example I will post it. – Mike S Apr 14 '15 at 17:50
Followup: If you, dear Traveller, are looking to utilize this code, I believe it has a number of errors in it. For example, the colons after "fred" and "barney" will cause salt to barf, as will the "end for" and "end if" (they should not have spaces in there). Again I suspect that the initial for construct is faulty but I don't know much about salt at this time so I can't be sure. Caveat Programmer. For myself, I'm going to work with the iteritems() concept. – Mike S Apr 14 '15 at 18:31
Fixed. Thanks, @MikeS – Dan Garthwaite Apr 14 '15 at 18:38
Sorry, Dan, I still get testminion: Data failed to compile: ---------- Rendering SLS 'base:users' failed: Jinja variable 'str object' has no attribute 'name' when I run: salt testminion state.highstate test=True ....I have copied your text verbatim, above. The only addition was my /srv/salt/top.sls file which is a simple 3-liner (base:, '*':, and -users). – Mike S Apr 14 '15 at 18:58
I'll spin up a docker container and sort it out, unless you get to it first? – Dan Garthwaite Apr 14 '15 at 19:11

protected by Community Aug 21 '14 at 18:17

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.