diff --git a/pillars/roles/git/saltmaster.sls b/pillars/roles/git/saltmaster.sls index 05d6f71..dc414ab 100644 --- a/pillars/roles/git/saltmaster.sls +++ b/pillars/roles/git/saltmaster.sls @@ -1,17 +1,18 @@ +{%- set branches=salt.cmd.shell('git ls-remote https://git.actcur.com/actcur/salt.git | grep -o -P "(?<=refs/heads/).*" | grep -Pv "(^temp$)|(^history$)"').split('\n') -%} +branches: + saltmaster: +{%- for branch in branches %} + - {{branch}} +{%- endfor %} + git: - salt: +{%- for branch in branches %} + salt_{{branch}}: repo: "ssh://gitea@git.actcur.com:5022/actcur/salt.git" - path: "/srv/salt/prod" - branch: "master" + path: "/srv/salt/{{branch}}" + branch: "{{branch}}" key: "git_actcur" - force: true - email: "actcur@actcur.com" - name: "Actaeus Curabitur" - salt_dev: - repo: "ssh://gitea@git.actcur.com:5022/actcur/salt.git" - path: "/srv/salt/dev" - branch: "dev" - key: "git_actcur" - force: true + force: {{ "True" if (branch == "prod" or branch == "qual") else "false" }} email: "actcur@actcur.com" name: "Actaeus Curabitur" +{%- endfor %} diff --git a/pillars/top.sls b/pillars/top.sls index a6637e3..61aec66 100644 --- a/pillars/top.sls +++ b/pillars/top.sls @@ -1,8 +1,7 @@ -prod: - '*': - - roles - - servers -dev: +{%- set branches=salt.cmd.shell('git ls-remote https://git.actcur.com/actcur/salt.git | grep -o -P "(?<=refs/heads/).*" | grep -Pv "(^temp$)|(^history$)"').split('\n') -%} +{%- for branch in branches %} +{{branch}}: '*': - roles - servers +{%- endfor %} diff --git a/merge.sh b/squash.sh similarity index 61% rename from merge.sh rename to squash.sh index 62b3b5a..51c9d09 100644 --- a/merge.sh +++ b/squash.sh @@ -3,17 +3,17 @@ git fetch --all; #copy dev to history to ensure we don't lose changes if something goes wrong git checkout history; -git reset --hard dev; +git reset --hard qual; git push --force; #merge to master -git checkout -B master origin/master; -git merge --squash dev; +git checkout -B prod origin/master; +git merge --squash qual; git commit -am "$cm"; git push; #clean dev -git checkout dev; -git reset --hard master; +git checkout qual; +git reset --hard prod; git push --force; -git reset --hard origin/dev; +git reset --hard origin/qual; diff --git a/states/roles/maintain/saltmaster/init.sls b/states/roles/maintain/saltmaster/init.sls index a569f50..b780236 100644 --- a/states/roles/maintain/saltmaster/init.sls +++ b/states/roles/maintain/saltmaster/init.sls @@ -1,5 +1,4 @@ {%- set os=grains['os'] -%} - salt-master: {%- if os=="CentOS" or os=="RedHat" %} pkg.installed: [] @@ -19,6 +18,7 @@ salt-master: - user: root - group: root - mode: 644 + - template: jinja /srv/salt/prod/states/pillars: file.symlink: diff --git a/states/roles/maintain/saltmaster/master b/states/roles/maintain/saltmaster/master index 45bce57..aea5fa0 100644 --- a/states/roles/maintain/saltmaster/master +++ b/states/roles/maintain/saltmaster/master @@ -422,12 +422,14 @@ state_output: terse # - /srv/salt/prod/states # file_roots: - base: - - /srv/salt/prod/states - prod: - - /srv/salt/prod/states - dev: - - /srv/salt/dev/states +{%- if pillar['branches'] is defined -%} +{%- if pillar['branches']['saltmaster'] is defined -%} +{%- for branch in pillar['branches']['saltmaster'] %} + {{branch}}: + - /srv/salt/{{branch}}/states +{%- endfor %} +{%- endif %} +{%- endif %} # # When using multiple environments, each with their own top file, the @@ -439,7 +441,15 @@ file_roots: # To specify the order in which environments are merged, set the ordering # in the env_order option. Given a conflict, the last matching value will # win. -env_order: ['base', 'dev', 'prod'] +{% if pillar['branches'] is defined -%} +{%- if pillar['branches']['saltmaster'] is defined -%} +env_order: [ +{%- for branch in pillar['branches']['saltmaster'] -%} + '{{-branch}}', +{%- endfor -%} +'null'] +{%- endif %} +{%- endif %} # If top_file_merging_strategy is set to 'same' and an environment does not # contain a top file, the top file in the environment specified by default_top @@ -560,12 +570,14 @@ hash_type: sha256 # - /srv/pillar # pillar_roots: - base: - - /srv/salt/prod/pillars - prod: - - /srv/salt/prod/pillars - dev: - - /srv/salt/dev/pillars +{%- if pillar['branches'] is defined -%} +{%- if pillar['branches']['saltmaster'] is defined -%} +{%- for branch in pillar['branches']['saltmaster'] %} + {{branch}}: + - /srv/salt/{{branch}}/pillars +{%- endfor %} +{%- endif %} +{%- endif %} # #ext_pillar: # - hiera: /etc/hiera.yaml diff --git a/states/test b/states/test new file mode 100644 index 0000000..89ca9da --- /dev/null +++ b/states/test @@ -0,0 +1,18 @@ +{%- set branches=salt.cmd.shell('git ls-remote https://git.actcur.com/actcur/salt.git | grep -o -P "(?<=refs/heads/).*" | grep -Pv "(^temp$)|(^history$)"').split('\n') -%} +branches: + saltmaster: +{%- for branch in branches %} + - {{branch}} +{%- endfor %} + +git: +{%- for branch in branches %} + salt_{{branch}}: + repo: "ssh://gitea@git.actcur.com:5022/actcur/salt.git" + path: "/srv/salt/{{branch}}" + branch: "{{branch}}" + key: "git_actcur" + force: {{ "True" if branch == "prod" else "false" }} + email: "actcur@actcur.com" + name: "Actaeus Curabitur" +{%- endfor %} diff --git a/states/test.sls b/states/test.sls new file mode 100644 index 0000000..e7db26e --- /dev/null +++ b/states/test.sls @@ -0,0 +1,4 @@ +/test: + file.managed: + - source: salt://test + - template: jinja diff --git a/states/top.sls b/states/top.sls index 3adcde1..302b1f7 100644 --- a/states/top.sls +++ b/states/top.sls @@ -1,6 +1,10 @@ {%- set states = salt['cp.list_states'](saltenv) -%} -{%- set envs = ['prod','dev'] -%} +{%- if pillar['branches'] is defined -%} +{%- if pillar['branches']['saltmaster'] is defined -%} +{%- set envs = pillar['branches']['saltmaster'] -%} +{%- endif -%} +{%- endif -%} {% for env in envs %} {{ env }}: 'os_family:RedHat':