From e4185f4add2a889b131a4784f98d9b64989c8ce2 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sat, 30 Mar 2019 22:57:23 +0000 Subject: [PATCH 1/5] fix(iteritems): replace with `items` instead --- cron/config.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cron/config.sls b/cron/config.sls index e66b4c8..3ccd9e3 100644 --- a/cron/config.sls +++ b/cron/config.sls @@ -4,7 +4,7 @@ {% from "cron/map.jinja" import cron_settings with context %} {% if 'tasks' in cron_settings %} -{% for task,task_options in cron_settings.tasks.iteritems() %} +{% for task,task_options in cron_settings.tasks.items() %} cron.{{ task }}: cron.{{ task_options.type|default('present') }}: From 0eaf78c6277827dcc782700bbef2af4e7733ce82 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sat, 30 Mar 2019 23:06:08 +0000 Subject: [PATCH 2/5] style(whitespace): base on multiples of `2` rather than `4` --- cron/config.sls | 60 ++++++++++++++++++++++----------------------- cron/init.sls | 6 ++--- cron/install.sls | 4 +-- cron/map.jinja | 32 ++++++++++++------------ cron/service.sls | 12 ++++----- pillar.example | 64 ++++++++++++++++++++++++------------------------ 6 files changed, 89 insertions(+), 89 deletions(-) diff --git a/cron/config.sls b/cron/config.sls index 3ccd9e3..a7a1cf9 100644 --- a/cron/config.sls +++ b/cron/config.sls @@ -7,35 +7,35 @@ {% for task,task_options in cron_settings.tasks.items() %} cron.{{ task }}: - cron.{{ task_options.type|default('present') }}: - - name: '{{ task_options.name }}' - {% if 'user' in task_options %} - - user: {{ task_options.user|default('root') }} - {% endif %} - {% if 'minute' in task_options %} - - minute: '{{ task_options.minute }}' - {% endif %} - {% if 'hour' in task_options %} - - hour: '{{ task_options.hour }}' - {% endif %} - {% if 'daymonth' in task_options %} - - daymonth: '{{ task_options.daymonth }}' - {% endif %} - {% if 'month' in task_options %} - - month: '{{ task_options.month }}' - {% endif %} - {% if 'dayweek' in task_options %} - - dayweek: '{{ task_options.dayweek }}' - {% endif %} - {% if 'commented' in task_options and task_options.commented %} - - commented: True - {% endif %} - {% if 'special' in task_options %} - - special: '{{ task_options.special }}' - {% endif %} - - identifier: '{{ task }}' - {% if 'comment' in task_options %} - - comment: '{{ task_options.comment }}' - {% endif %} + cron.{{ task_options.type|default('present') }}: + - name: '{{ task_options.name }}' + {% if 'user' in task_options %} + - user: {{ task_options.user|default('root') }} + {% endif %} + {% if 'minute' in task_options %} + - minute: '{{ task_options.minute }}' + {% endif %} + {% if 'hour' in task_options %} + - hour: '{{ task_options.hour }}' + {% endif %} + {% if 'daymonth' in task_options %} + - daymonth: '{{ task_options.daymonth }}' + {% endif %} + {% if 'month' in task_options %} + - month: '{{ task_options.month }}' + {% endif %} + {% if 'dayweek' in task_options %} + - dayweek: '{{ task_options.dayweek }}' + {% endif %} + {% if 'commented' in task_options and task_options.commented %} + - commented: True + {% endif %} + {% if 'special' in task_options %} + - special: '{{ task_options.special }}' + {% endif %} + - identifier: '{{ task }}' + {% if 'comment' in task_options %} + - comment: '{{ task_options.comment }}' + {% endif %} {% endfor %} {% endif %} diff --git a/cron/init.sls b/cron/init.sls index eff3fc8..74ad02e 100644 --- a/cron/init.sls +++ b/cron/init.sls @@ -2,6 +2,6 @@ # vim: ft=sls include: - - cron.install - - cron.config - - cron.service + - cron.install + - cron.config + - cron.service diff --git a/cron/install.sls b/cron/install.sls index 6083ed1..2676d26 100644 --- a/cron/install.sls +++ b/cron/install.sls @@ -4,5 +4,5 @@ {% from "cron/map.jinja" import cron_settings with context %} cron.install: - pkg.installed: - - name: {{ cron_settings.pkg }} + pkg.installed: + - name: {{ cron_settings.pkg }} diff --git a/cron/map.jinja b/cron/map.jinja index d91a7db..56fd898 100644 --- a/cron/map.jinja +++ b/cron/map.jinja @@ -2,23 +2,23 @@ # vim: ft=jinja {% set os_family_map = salt['grains.filter_by']({ - 'RedHat': { - 'pkg': 'cronie', - 'service': 'crond', - }, - 'Suse': { - 'pkg': 'cronie', - 'service': 'cron', - }, - 'Debian': { - 'pkg': 'cron', - 'service': 'cron', - }, + 'RedHat': { + 'pkg': 'cronie', + 'service': 'crond', + }, + 'Suse': { + 'pkg': 'cronie', + 'service': 'cron', + }, + 'Debian': { + 'pkg': 'cron', + 'service': 'cron', + }, }, grain='os_family', merge=salt['pillar.get']('cron:lookup')) %} {% set cron_settings = salt['pillar.get']( - 'cron', - default=os_family_map, - merge=True - ) + 'cron', + default=os_family_map, + merge=True + ) %} diff --git a/cron/service.sls b/cron/service.sls index ea11acc..bd20ea4 100644 --- a/cron/service.sls +++ b/cron/service.sls @@ -5,11 +5,11 @@ cron.service: {% if 'enabled' not in cron_settings or ( 'enabled' in cron_settings and cron_settings.enabled ) %} - service.running: - - name: {{ cron_settings.service }} - - enable: True + service.running: + - name: {{ cron_settings.service }} + - enable: True {% else %} - service.dead: - - name: {{ cron_settings.service }} - - enable: False + service.dead: + - name: {{ cron_settings.service }} + - enable: False {% endif %} diff --git a/pillar.example b/pillar.example index fceb4d5..f7137e9 100644 --- a/pillar.example +++ b/pillar.example @@ -1,33 +1,33 @@ cron: - enabled: True # Default - lookup: # Not needed, just if you want to use another cron program - pkg: 'cronie' - tasks: - task1: - type: 'present' # Default - name: 'echo test > /tmp/test' - user: 'root' - minute: 0 - hour: 0 - daymonth: 7 - month: 1 - dayweek: 6 - comment: 'comment1' - task2: - type: 'absent' # To remove that crontask - name: 'echo task2 > /tmp/test2' - user: 'root' - minute: 'random' - hour: 1 - task3: - type: 'absent' - name: 'echo task3 > /tmp/test3' - user: 'root' - special: '@hourly' - comment: 'comment3' - task4: - type: 'present' # run every 5 minutes - user: 'root' - minute: '*/5' - hour: '*' - comment: 'comment4' + enabled: True # Default + lookup: # Not needed, just if you want to use another cron program + pkg: 'cronie' + tasks: + task1: + type: 'present' # Default + name: 'echo test > /tmp/test' + user: 'root' + minute: 0 + hour: 0 + daymonth: 7 + month: 1 + dayweek: 6 + comment: 'comment1' + task2: + type: 'absent' # To remove that crontask + name: 'echo task2 > /tmp/test2' + user: 'root' + minute: 'random' + hour: 1 + task3: + type: 'absent' + name: 'echo task3 > /tmp/test3' + user: 'root' + special: '@hourly' + comment: 'comment3' + task4: + type: 'present' # run every 5 minutes + user: 'root' + minute: '*/5' + hour: '*' + comment: 'comment4' From 2d1f7c2601750832e01943bbf1708ba5efa5469e Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sat, 30 Mar 2019 23:10:19 +0000 Subject: [PATCH 3/5] style(jinja): use Jinja whitespace control --- cron/config.sls | 46 +++++++++++++++++++++++----------------------- cron/install.sls | 2 +- cron/map.jinja | 4 ++-- cron/service.sls | 8 ++++---- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/cron/config.sls b/cron/config.sls index a7a1cf9..73954d6 100644 --- a/cron/config.sls +++ b/cron/config.sls @@ -1,41 +1,41 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{% from "cron/map.jinja" import cron_settings with context %} +{%- from "cron/map.jinja" import cron_settings with context %} -{% if 'tasks' in cron_settings %} -{% for task,task_options in cron_settings.tasks.items() %} +{%- if 'tasks' in cron_settings %} +{%- for task,task_options in cron_settings.tasks.items() %} cron.{{ task }}: cron.{{ task_options.type|default('present') }}: - name: '{{ task_options.name }}' - {% if 'user' in task_options %} + {%- if 'user' in task_options %} - user: {{ task_options.user|default('root') }} - {% endif %} - {% if 'minute' in task_options %} + {%- endif %} + {%- if 'minute' in task_options %} - minute: '{{ task_options.minute }}' - {% endif %} - {% if 'hour' in task_options %} + {%- endif %} + {%- if 'hour' in task_options %} - hour: '{{ task_options.hour }}' - {% endif %} - {% if 'daymonth' in task_options %} + {%- endif %} + {%- if 'daymonth' in task_options %} - daymonth: '{{ task_options.daymonth }}' - {% endif %} - {% if 'month' in task_options %} + {%- endif %} + {%- if 'month' in task_options %} - month: '{{ task_options.month }}' - {% endif %} - {% if 'dayweek' in task_options %} + {%- endif %} + {%- if 'dayweek' in task_options %} - dayweek: '{{ task_options.dayweek }}' - {% endif %} - {% if 'commented' in task_options and task_options.commented %} + {%- endif %} + {%- if 'commented' in task_options and task_options.commented %} - commented: True - {% endif %} - {% if 'special' in task_options %} + {%- endif %} + {%- if 'special' in task_options %} - special: '{{ task_options.special }}' - {% endif %} + {%- endif %} - identifier: '{{ task }}' - {% if 'comment' in task_options %} + {%- if 'comment' in task_options %} - comment: '{{ task_options.comment }}' - {% endif %} -{% endfor %} -{% endif %} + {%- endif %} +{%- endfor %} +{%- endif %} diff --git a/cron/install.sls b/cron/install.sls index 2676d26..91baef8 100644 --- a/cron/install.sls +++ b/cron/install.sls @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{% from "cron/map.jinja" import cron_settings with context %} +{%- from "cron/map.jinja" import cron_settings with context %} cron.install: pkg.installed: diff --git a/cron/map.jinja b/cron/map.jinja index 56fd898..5b107f9 100644 --- a/cron/map.jinja +++ b/cron/map.jinja @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # vim: ft=jinja -{% set os_family_map = salt['grains.filter_by']({ +{%- set os_family_map = salt['grains.filter_by']({ 'RedHat': { 'pkg': 'cronie', 'service': 'crond', @@ -16,7 +16,7 @@ }, }, grain='os_family', merge=salt['pillar.get']('cron:lookup')) %} -{% set cron_settings = salt['pillar.get']( +{%- set cron_settings = salt['pillar.get']( 'cron', default=os_family_map, merge=True diff --git a/cron/service.sls b/cron/service.sls index bd20ea4..1e46a94 100644 --- a/cron/service.sls +++ b/cron/service.sls @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- # vim: ft=sls -{% from "cron/map.jinja" import cron_settings with context %} +{%- from "cron/map.jinja" import cron_settings with context %} cron.service: -{% if 'enabled' not in cron_settings or ( 'enabled' in cron_settings and cron_settings.enabled ) %} +{%- if 'enabled' not in cron_settings or ( 'enabled' in cron_settings and cron_settings.enabled ) %} service.running: - name: {{ cron_settings.service }} - enable: True -{% else %} +{%- else %} service.dead: - name: {{ cron_settings.service }} - enable: False -{% endif %} +{%- endif %} From 01a858a23e1da44e274a1c7a947aa3b0923f4044 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sat, 30 Mar 2019 23:32:25 +0000 Subject: [PATCH 4/5] fix(pillar): add job for `task4` --- pillar.example | 1 + 1 file changed, 1 insertion(+) diff --git a/pillar.example b/pillar.example index f7137e9..44eb0cd 100644 --- a/pillar.example +++ b/pillar.example @@ -27,6 +27,7 @@ cron: comment: 'comment3' task4: type: 'present' # run every 5 minutes + name: 'echo task4 > /tmp/test4' user: 'root' minute: '*/5' hour: '*' From 8ee7ffa2828885ec1cb908d875b9f610416e1df5 Mon Sep 17 00:00:00 2001 From: Imran Iqbal Date: Sun, 31 Mar 2019 00:58:35 +0000 Subject: [PATCH 5/5] fix(quotes): remove single quotes causing issues (or unnecessary) * Allow single quotes to be used in commands and comments, e.g.: - /usr/bin/salt '*' test.ping >/root/salt_test_ping --- cron/config.sls | 4 ++-- pillar.example | 38 +++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/cron/config.sls b/cron/config.sls index 73954d6..55748eb 100644 --- a/cron/config.sls +++ b/cron/config.sls @@ -8,7 +8,7 @@ cron.{{ task }}: cron.{{ task_options.type|default('present') }}: - - name: '{{ task_options.name }}' + - name: {{ task_options.name }} {%- if 'user' in task_options %} - user: {{ task_options.user|default('root') }} {%- endif %} @@ -35,7 +35,7 @@ cron.{{ task }}: {%- endif %} - identifier: '{{ task }}' {%- if 'comment' in task_options %} - - comment: '{{ task_options.comment }}' + - comment: {{ task_options.comment }} {%- endif %} {%- endfor %} {%- endif %} diff --git a/pillar.example b/pillar.example index 44eb0cd..ab93d14 100644 --- a/pillar.example +++ b/pillar.example @@ -1,34 +1,34 @@ cron: - enabled: True # Default - lookup: # Not needed, just if you want to use another cron program - pkg: 'cronie' + enabled: True # Default + lookup: # Not needed, just if you want to use another cron program + pkg: cronie tasks: task1: - type: 'present' # Default - name: 'echo test > /tmp/test' - user: 'root' + type: present # Default + name: echo test > /tmp/test + user: root minute: 0 hour: 0 daymonth: 7 month: 1 dayweek: 6 - comment: 'comment1' + comment: comment1 task2: - type: 'absent' # To remove that crontask - name: 'echo task2 > /tmp/test2' - user: 'root' - minute: 'random' + type: absent # To remove that crontask + name: echo task2 > /tmp/test2 + user: root + minute: random hour: 1 task3: - type: 'absent' - name: 'echo task3 > /tmp/test3' - user: 'root' + type: absent + name: echo task3 > /tmp/test3 + user: root special: '@hourly' - comment: 'comment3' + comment: comment3 task4: - type: 'present' # run every 5 minutes - name: 'echo task4 > /tmp/test4' - user: 'root' + type: present # run every 5 minutes + name: echo task4 > /tmp/test4 + user: root minute: '*/5' hour: '*' - comment: 'comment4' + comment: comment4