Skip to content

Commit

Permalink
fix(*): fix to allow deployment with salt-ssh.
Browse files Browse the repository at this point in the history
Basically use tplroot in sls files and pass vars used in templates through the context.
  • Loading branch information
VBH-Jenkins committed Sep 4, 2019
1 parent b59500c commit 34411bb
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 23 deletions.
3 changes: 2 additions & 1 deletion salt/api.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
include:
- salt.master
Expand Down
5 changes: 4 additions & 1 deletion salt/cloud.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
{%- if salt_settings.use_pip %}
python-pip:
Expand Down Expand Up @@ -59,6 +60,8 @@ salt-cloud-{{ cloud_section }}:
- template: jinja
- makedirs: True
- exclude_pat: _*
- context:
salt_settings: {{ salt_settings|json }}
{% for filename in salt['pillar.get']("salt:cloud:" ~ cloud_section, {}).keys() %}
/etc/salt/cloud.{{ cloud_section }}.d/{{ filename }}:
Expand Down
3 changes: 2 additions & 1 deletion salt/files/cloud.providers.d/_ec2.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file managed by Salt, do not edit by hand!!
{%- from "salt/map.jinja" import salt_settings with context -%}
{#- Provided via context -#}
{#- from "salt/map.jinja" import salt_settings with context -#}
{%- set cloud = salt['pillar.get']('salt:cloud', {}) -%}
{%- if 'aws_key' in cloud %}
ec2_ubuntu_public:
Expand Down
3 changes: 2 additions & 1 deletion salt/files/cloud.providers.d/_gce.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file managed by Salt, do not edit by hand!!
{%- from "salt/map.jinja" import salt_settings with context -%}
{#- Provided via context -#}
{#- from "salt/map.jinja" import salt_settings with context -#}
{%- set cloud = salt['pillar.get']('salt:cloud', {}) -%}
{%- if 'gce_project' in cloud %}
gce:
Expand Down
6 changes: 5 additions & 1 deletion salt/files/master.d/f_defaults.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# This file managed by Salt, do not edit by hand!!
# Based on salt version 2016.11 default config
#
{% set reserved_keys = ['master', 'minion', 'cloud', 'salt_cloud_certs', 'engines', 'lxc.network_profile', 'lxc.container_profile', 'reactors'] -%}
{% set cfg_salt = pillar.get('salt', {}) -%}
{% set cfg_master = cfg_salt.get('master', {}) -%}
Expand All @@ -14,7 +15,10 @@
#{{ configname }}: {{ default_value|json }}
{%- endif -%}
{%- endmacro -%}
{%- from 'salt/formulas.jinja' import file_roots, formulas with context -%}

{#- Provided via context -#}
{#- from 'salt/formulas.jinja' import file_roots, formulas with context -#}

##### Primary configuration settings #####
##########################################
# This configuration file is used to manage the behavior of the Salt Master.
Expand Down
4 changes: 3 additions & 1 deletion salt/files/minion.d/f_defaults.conf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#{{ configname }}: {{ default_value|json }}
{%- endif -%}
{%- endmacro -%}
{%- from 'salt/formulas.jinja' import file_roots, formulas with context -%}

{#- Provided via context -#}
{#- from 'salt/formulas.jinja' import file_roots, formulas with context -#}

##### Primary configuration settings #####
##########################################
Expand Down
7 changes: 2 additions & 5 deletions salt/formulas.sls
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
{%- set processed_gitdir_envs = [] %}
{%- set processed_basedirs = [] %}

{%- from "salt/map.jinja" import formulas_settings with context %}
{%- from "salt/formulas.jinja" import formulas_git_opt with context %}
{%- from "salt/formulas.jinja" import formulas_opts_for_git_latest with context %}
## from template-formula
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
{%- from tplroot ~ "/map.jinja" import salt_settings, formulas_settings with context %}
{%- from tplroot ~ "/formulas.jinja" import formulas_git_opt, formulas_opts_for_git_latest with context %}
# Loop over all formulas listed in pillar data
{%- for env, entries in salt['pillar.get']('salt_formulas:list', {}).items() %}
Expand Down
7 changes: 4 additions & 3 deletions salt/map.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# vim: ft=jinja

{## Start imports ##}
{% import_yaml "salt/defaults.yaml" as defaults %}
{% import_yaml "salt/osfamilymap.yaml" as osfamilymap %}
{% import_yaml "salt/osmap.yaml" as osmap %}
{%- set tplroot = tpldir.split('/')[0] %}
{% import_yaml tplroot ~ "/defaults.yaml" or {} as defaults %}
{% import_yaml tplroot ~ "/osfamilymap.yaml" or {} as osfamilymap %}
{% import_yaml tplroot ~ "/osmap.yaml" or {} as osmap %}

{# merge the osfamilymap #}
{% set osfamily = salt['grains.filter_by'](osfamilymap, grain='os_family') or{} %}
Expand Down
4 changes: 4 additions & 0 deletions salt/master.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- from tplroot ~ "/formulas.jinja" import file_roots, formulas with context %}
salt-master:
{% if salt_settings.install_packages %}
Expand All @@ -25,6 +26,9 @@ salt-master:
{%- else %}
- template: jinja
- source: salt://{{ slspath }}/files/master.d
- context:
file_roots: {{ file_roots }}
formulas: {{ formulas|json }}
{%- endif %}
- clean: {{ salt_settings.clean_config_d_dir }}
- exclude_pat: _*
Expand Down
3 changes: 3 additions & 0 deletions salt/minion.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
{%- from tplroot ~ "/libtofs.jinja" import files_switch with context %}
{%- from tplroot ~ "/formulas.jinja" import file_roots, formulas with context %}
{% if salt_settings.install_packages and grains.os == 'MacOS' %}
download-salt-minion:
Expand Down Expand Up @@ -68,6 +69,8 @@ salt-minion:
- source: salt://{{ slspath }}/files/minion.d
- context:
standalone: False
file_roots: {{ file_roots }}
formulas: {{ formulas|json }}
{%- endif %}
- clean: {{ salt_settings.clean_config_d_dir }}
- exclude_pat: _*
Expand Down
3 changes: 2 additions & 1 deletion salt/pkgrepo/debian/clean.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
salt-pkgrepo-clean-saltstack-debian:
pkgrepo.absent:
Expand Down
3 changes: 2 additions & 1 deletion salt/pkgrepo/debian/install.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
salt-pkgrepo-install-saltstack-debian:
pkgrepo.managed:
Expand Down
7 changes: 4 additions & 3 deletions salt/pkgrepo/redhat/install.sls
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
{%- if grains['os']|lower not in ('amazon', 'fedora') %}
{%- if grains['os']|lower not in ('amazon', 'fedora') %}
salt-pkgrepo-install-saltstack-redhat:
pkgrepo.managed:
- name: saltstack
Expand All @@ -11,4 +12,4 @@ salt-pkgrepo-install-saltstack-redhat:
- enabled: 1
- gpgcheck: 1
- gpgkey: {{ salt_settings.key_url }}
{% endif %}
{% endif %}
3 changes: 2 additions & 1 deletion salt/pkgrepo/suse/install.sls
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# vim: ft=sls
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
salt-pkgrepo-install-saltstack-suse:
pkgrepo.managed:
Expand Down
4 changes: 3 additions & 1 deletion salt/ssh.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% from "salt/map.jinja" import salt_settings with context %}
## from template-formula
{%- set tplroot = tpldir.split('/')[0] %}
{% from tplroot ~ "/map.jinja" import salt_settings with context %}
{% if salt_settings.install_packages %}
ensure-salt-ssh-is-installed:
Expand Down
5 changes: 4 additions & 1 deletion salt/standalone.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
salt-minion:
{% if salt_settings.install_packages %}
Expand All @@ -16,6 +17,8 @@ salt-minion:
- exclude_pat: _*
- context:
standalone: True
file_roots: {{ file_roots }}
formulas: {{ formulas|json }}
{%- if salt_settings.minion.master_type is defined and salt_settings.minion.master_type == 'disable' %}
service.running:
- enable: True
Expand Down
3 changes: 2 additions & 1 deletion salt/syndic.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% from "salt/map.jinja" import salt_settings with context %}
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import salt_settings with context %}
include:
- salt.master
Expand Down

0 comments on commit 34411bb

Please sign in to comment.