Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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....

/xxx/yyy/zzz/id_rsa:
  file.managed:
   - source: salt://private/id_rsa

/xxx/yyy/zz/id_rsa.pub:
  file.managed:
 - source: salt://private/id_rsa.pub

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

ssh:
  file.managed:
    - 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

1 Answer 1

up vote 3 down vote accepted

Pillars 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.

Here is an overview of what you want to do.

file: /srv/salt/user/init.sls

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

  user.present:
    - name: {{user.name}}
    - fullname: {{user.fullname}}
    - password: {{user.shadow}}
    - shell: {{user.shell}}
    - uid: {{user.uid}}
    - gid: {{user.gid}}
    {% if user.groups %}
    - optional_groups:
      {% for group in user.groups %}
      - {{group}}
      {% end for %}
    {% end if %}
    - require:
      - group: user_{{user.name}}

  file.directory:
    - name: /home/{{user.name}}
    - user: {{user.name}}
    - group: {{user.name}}
    - mode: 0751
    - makedirs: True
    - unless:
      - ls -nd /home/{{user.name}} | grep -q "{{user.uid}} {{user.gid}}"

user_{{user.name}}_authkeys:
  ssh_auth.present:
    - user: {{user.name}}
    - source: salt://user/blank.jinja
    - template: jinja
    - defaults:
        body: user.authkey
    - require:
      - file: user_{{user.name}}

user_{{user.name}}_sshdir:
  file.directory:
    - name: /home/{{user.name}}/.ssh
    - user: {{user.name}}
    - group: {{user.name}}
    - mode: 0700
    - require:
      - file: user_{{user.name}}

user_{{user.name}}_sshpriv:
  file.managed:
    - user: {{user.name}}
    - group: {{user.name}}
    - mode: 0600
    - contents_pillar: users:{{user.name}}:user.sshpriv
    - require:
      - file: user_{{user.name}}_sshdir

user_{{user.name}}_sshpub:
  file.managed:
    - user: {{user.name}}
    - group: {{user.name}}
    - mode: 0600
    - contents_pillar: users:{{user.name}}:user.sshpub
    - require:
      - file: user_{{user.name}}_sshdir

user_{{user.name}}_forward:
  file.append:
    - name: /home/{{user.name}}/.forward
    - text: {{user.email}}
    - require:
      - file: user_{{user.name}}

{% endfor %} # user in users
# vim: ft=yaml tabstop=2 sts=2 sw=2 et ai si

Wire up pillars:

/srv/pillar/top.sls

base:
  'testminion':
    - users.sls

# vim: ft=yaml

Fill up the pillar of users:

/srv/pillar/users.sls

users:
  fred:
    name: fred:
    fullname: Fred Flintstone
    email: fflintstone@slaterockandgravel.com
    uid: 4001
    gid: 4001
    shell: /bin/bash
    groups:
      - bowling
    shadow: $6$Sasdf/Ss$asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfasdfsadfsadfsdf

    user.sshpub: ssh-dss AAAAasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafaasdfasdfasdfasdfasdfsadfsadfsadfsadfasdfasdfsdafsdafa = fflinstone@slaterockandgravel.com

    user.sshpriv: |
        -----BEGIN DSA PRIVATE KEY-----
        Proc-Type: 4,ENCRYPTED
        DEK-Info: DES-EDE3-CBC,093280928309283

        PU7iy+asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfsadfsa
        asdfasasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfsadfsa
        asdfasasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfsadfsa
        asdfasasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfsadfsadfsa
        asdfasdfasdfasdfasdfasdfasdfasdf
        -----END DSA PRIVATE KEY-----

  barney:
    name: barney:
    fullname: Barney Rubble
    email: brubbel@slaterockandgravel.com
    uid: 4002
    gid: 4002
    shell: /bin/bash
    groups:
      - bowling
    shadow: $6$Suiop/Ss$uiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopsadfuiopsadfsadfsdf

    user.sshpub: ssh-dss AAAAuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafauiopuiopuiopuiopuiopsadfsadfsadfsadfuiopuiopsdafsdafa = fflinstone@slaterockandgravel.com

    user.sshpriv: |
        -----BEGIN DSA PRIVATE KEY-----
        Proc-Type: 4,ENCRYPTED
        DEK-Info: DES-EDE3-CBC5,34534245435

        PU7iy+uiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopsadfsadfsa
        uiopasuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopsadfsadfsa
        uiopasuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopsadfsadfsa
        uiopasuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopuiopsadfsadfsa
        uiopuiopuiopuiopuiopuiopuiopuiop
        -----END DSA PRIVATE KEY-----

# vim: ft=yaml

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

salt targetminions saltutil.refresh_pillar
share|improve this answer

protected by Community Aug 21 at 18:17

Thank you for your interest in this question. Because it has attracted low-quality answers, 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.