Skip to content

Instantly share code, notes, and snippets.

@carsten-AEI
Created June 9, 2016 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carsten-AEI/c34d4059bb91b2e758ccb8d8c0322e98 to your computer and use it in GitHub Desktop.
Save carsten-AEI/c34d4059bb91b2e758ccb8d8c0322e98 to your computer and use it in GitHub Desktop.
# take care of home directory autofs there
include:
- common.remote-home
autofs:
pkg.installed
# there are currently three different cases to consider
# (1) file based map
# (2) executable, self-contained script
# (3) executable plus external map file
# due to repitition one could also try to make this file more
# concise but more complex with some more jinja magic
# define arrays for static and executable mappings
{% set atlas_autofs_static = ['opt','user'] %}
{% set atlas_autofs_dynamic = ['ldr','recent'] %}
{% set atlas_autofs_dynamic_map = ['data'] %}
# the mount point needs to exist for all
{% for snippet in atlas_autofs_static|list + atlas_autofs_dynamic|list + atlas_autofs_dynamic_map|list %}
/atlas/{{ snippet }}:
file.directory:
- user: root
- group: root
- dir_mode: 0755
- makedirs: True
# also then master.d snippet
/etc/auto.master.d/{{ snippet }}.autofs:
file.managed:
- source: salt://atlas/autofs/files/etc/auto.master.d/{{ snippet }}.autofs
- makedirs: True
- mode: 0644
# the main file may be executable
/etc/auto.{{ snippet }}:
file.managed:
- source: salt://atlas/autofs/files/etc/auto.{{ snippet }}
{% if snippet in atlas_autofs_static %}
- mode: 0644
{% else %}
- mode: 0755
{% endif %}
{% endfor %}
# some need map files
{% for snippet in atlas_autofs_dynamic_map %}
/etc/auto.{{ snippet }}.map:
file.managed:
- source: salt://atlas/autofs/files/etc/auto.{{ snippet }}.map
- mode: 0644
{% endfor %}
atlas-autofs-reload:
service.running:
- name: autofs
- reload: True
- watch:
{% for s in atlas_autofs_static|list + atlas_autofs_dynamic|list + atlas_autofs_dynamic_map|list %}
- file: /etc/auto.master.d/{{ s }}.autofs
- file: /etc/auto.{{ s }}
{% endfor %}
{% for s in atlas_autofs_dynamic_map %}
- file: /etc/auto.{{ s }}.map
{% endfor %}
{% set home_autofs = [] %}
{% for details in salt['pillar.get']('common:users:accounts', {}).itervalues() %}
{# only map autofs-homes that are mounted at /home (also enforced by DB triggers) #}
{% if details['autofs_location'] and details['home'] | truncate(6,True,'') == '/home/' %}
{% do home_autofs.append(details['home'] | replace('/home/','') + ' ' + details['autofs_location']) %}
{% endif %}
{% endfor %}
{% if home_autofs %}
autofs:
pkg.installed
autofs-functions:
file.managed:
- name: /etc/auto.functions
- source: salt://common/remote-home/files/etc/auto.functions
autofs-home-script:
file.managed:
- name: /etc/auto.home
- source: salt://common/remote-home/files/etc/auto.home
- mode: 755
autofs-home-map:
file.managed:
- name: /etc/auto.home.map
- contents: |
{{ home_autofs | sort | join('\n') | indent(8) }}
autofs-home-enable:
file.managed:
- name: /etc/auto.master.d/home.autofs
- makedirs: True
- contents: '/home program:/etc/auto.home --timeout=300'
autofs-reload:
service.running:
- name: autofs
- reload: True
- watch:
- file: autofs-functions
- file: autofs-home-script
- file: autofs-home-map
- file: autofs-home-enable
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment