From 0a2468d87ae71a927d3000987854b76c06d41d4b Mon Sep 17 00:00:00 2001 From: Kenny Do Date: Fri, 3 Jan 2014 16:54:51 -0800 Subject: [PATCH 1/2] created a map.jinja and updated openssh state to use those values --- openssh/init.sls | 21 ++++++++++----------- openssh/map.jinja | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 openssh/map.jinja diff --git a/openssh/init.sls b/openssh/init.sls index 6ea329b..f70539d 100644 --- a/openssh/init.sls +++ b/openssh/init.sls @@ -1,25 +1,24 @@ +{% from "openssh/map.jinja" import openssh with context %} + openssh: - pkg: - - installed - {% if grains['os_family'] == 'Debian' %} - - name: openssh-server - {% endif %} + pkg.installed: + - name: {{ openssh.server }} service.running: - enable: True - - name: ssh + - name: {{ openssh.service }} - require: - - pkg: openssh + - pkg: {{ openssh.server }} - file: sshd_banner - watch: - file: sshd_config sshd_config: file.managed: - - name: /etc/ssh/sshd_config - - source: salt://openssh/files/sshd_config + - name: {{ openssh.sshd_config }} + - source: {{ openssh.sshd_config_src }} sshd_banner: file.managed: - - name: /etc/ssh/banner - - source: salt://openssh/files/banner + - name: {{ openssh.banner }} + - source: {{ openssh.banner_src }} - template: jinja diff --git a/openssh/map.jinja b/openssh/map.jinja new file mode 100644 index 0000000..9376e5e --- /dev/null +++ b/openssh/map.jinja @@ -0,0 +1,18 @@ +{% set openssh = salt['grains.filter_by']({ + 'Debian': { + 'server': 'openssh-server', + 'service': 'ssh', + 'sshd_config': '/etc/ssh/sshd_config', + 'sshd_config_src': 'salt://openssh/files/sshd_config', + 'banner': '/etc/ssh/banner', + 'banner_src': 'salt://openssh/files/banner', + }, + 'RedHat': { + 'server': 'openssh-server', + 'service': 'sshd', + 'sshd_config': '/etc/ssh/sshd_config', + 'sshd_config_src': 'salt://openssh/files/sshd_config', + 'banner': '/etc/ssh/banner', + 'banner_src': 'salt://openssh/files/banner', + }, +}, merge=salt['pillar.get']('openssh:lookup')) %} From 07771c0ebfd08541123c1a8a91e9989e23f94cfb Mon Sep 17 00:00:00 2001 From: Kenny Do Date: Fri, 3 Jan 2014 18:32:05 -0800 Subject: [PATCH 2/2] Split the sshd_config and banner components into sub-states --- README.rst | 13 +++++++++---- openssh/banner.sls | 10 ++++++++++ openssh/config.sls | 12 ++++++++++++ openssh/init.sls | 13 ------------- 4 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 openssh/banner.sls create mode 100644 openssh/config.sls diff --git a/README.rst b/README.rst index 119f98f..37669a1 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,12 @@ openssh ======= +Install and configure an openssh server. -openssh -------- - -Install openssh and set up the daemon, install a useful banner as well +States +------ +``openssh`` + Installs the ``openssh`` package and service. +``openssh.config`` + Installs the configuration file included in this formula (under "openssh/files"). +``openssh.banner`` + Installs a banner that users see when SSH-ing in. diff --git a/openssh/banner.sls b/openssh/banner.sls new file mode 100644 index 0000000..f301a09 --- /dev/null +++ b/openssh/banner.sls @@ -0,0 +1,10 @@ +{% from "openssh/map.jinja" import openssh with context %} + +include: + - openssh + +sshd_banner: + file.managed: + - name: {{ openssh.banner }} + - source: {{ openssh.banner_src }} + - template: jinja diff --git a/openssh/config.sls b/openssh/config.sls new file mode 100644 index 0000000..cbf7376 --- /dev/null +++ b/openssh/config.sls @@ -0,0 +1,12 @@ +{% from "openssh/map.jinja" import openssh with context %} + +include: + - openssh + +sshd_config: + file.managed: + - name: {{ openssh.sshd_config }} + - source: {{ openssh.sshd_config_src }} + - watch_in: + - service: {{ openssh.service }} + diff --git a/openssh/init.sls b/openssh/init.sls index f70539d..9069302 100644 --- a/openssh/init.sls +++ b/openssh/init.sls @@ -8,17 +8,4 @@ openssh: - name: {{ openssh.service }} - require: - pkg: {{ openssh.server }} - - file: sshd_banner - - watch: - - file: sshd_config -sshd_config: - file.managed: - - name: {{ openssh.sshd_config }} - - source: {{ openssh.sshd_config_src }} - -sshd_banner: - file.managed: - - name: {{ openssh.banner }} - - source: {{ openssh.banner_src }} - - template: jinja