From 741a795e70102db5607283c72f771bb730b0a7e5 Mon Sep 17 00:00:00 2001 From: Simon Baerlocher Date: Fri, 8 May 2020 16:11:25 +0200 Subject: [PATCH 1/2] add scheduled_tasks role --- docs/index.html | 48 ++++++++++--------- roles/scheduled_tasks/README.md | 39 +++++++++++++++ roles/scheduled_tasks/defaults/main.yml | 25 ++++++++++ roles/scheduled_tasks/meta/main.yml | 16 +++++++ .../molecule/default/molecule.yml | 21 ++++++++ .../molecule/default/playbook.yml | 5 ++ roles/scheduled_tasks/tasks/main.yml | 10 ++++ .../scheduled_tasks/tasks/scheduled_task.yml | 38 +++++++++++++++ 8 files changed, 180 insertions(+), 22 deletions(-) create mode 100644 roles/scheduled_tasks/README.md create mode 100644 roles/scheduled_tasks/defaults/main.yml create mode 100644 roles/scheduled_tasks/meta/main.yml create mode 100644 roles/scheduled_tasks/molecule/default/molecule.yml create mode 100644 roles/scheduled_tasks/molecule/default/playbook.yml create mode 100644 roles/scheduled_tasks/tasks/main.yml create mode 100644 roles/scheduled_tasks/tasks/scheduled_task.yml diff --git a/docs/index.html b/docs/index.html index 9789dd5..33c3616 100644 --- a/docs/index.html +++ b/docs/index.html @@ -24,28 +24,28 @@ nav: [ { title: 'Home', - link: '/' + link: '/', }, { title: 'GitHub', - link: 'https://github.com/sbaerlocher/ansible.windows' + link: 'https://github.com/sbaerlocher/ansible.windows', }, { title: 'Ansible Galaxy', - link: 'https://galaxy.ansible.com/sbaerlocher/windows' - } + link: 'https://galaxy.ansible.com/sbaerlocher/windows', + }, ], overrides: { '/': { - language: 'English' // Used by the language dropdown menu in the sidebar - } + language: 'English', // Used by the language dropdown menu in the sidebar + }, }, // Use `versions` option to add a version selector // In the sidebar versions: { Latest: { - link: '/' - } + link: '/', + }, }, sidebar: [ // A sidebar item, with child links @@ -54,52 +54,56 @@ children: [ { title: 'Defender', - link: '/roles/defender/README' + link: '/roles/defender/README', }, { title: 'Directories', - link: '/roles/directories/README' + link: '/roles/directories/README', }, { title: 'Disks', - link: '/roles/disks/README' + link: '/roles/disks/README', }, { title: 'Local Administrators', - link: '/roles/local_administrators/README' + link: '/roles/local_administrators/README', }, { title: 'Membership', - link: '/roles/membership/README' + link: '/roles/membership/README', }, { title: 'OneDrive', - link: '/roles/onedrive/README' + link: '/roles/onedrive/README', }, { title: 'Optional Features', - link: '/roles/optional_features/README' + link: '/roles/optional_features/README', }, { title: 'Power Plan', - link: '/roles/power_plan/README' + link: '/roles/power_plan/README', + }, + { + title: 'Scheduled Tasks', + link: '/roles/scheduled_tasks/README', }, { title: 'Remote Desktop', - link: '/roles/remote_desktop/README' + link: '/roles/remote_desktop/README', }, { title: 'Startlayout', - link: '/roles/startlayout/README' - } - ] - } + link: '/roles/startlayout/README', + }, + ], + }, ], footer: `
© ${new Date().getFullYear()} sbaerlocher. Released under MIT license.
- ` + `, }); diff --git a/roles/scheduled_tasks/README.md b/roles/scheduled_tasks/README.md new file mode 100644 index 0000000..8f1b39e --- /dev/null +++ b/roles/scheduled_tasks/README.md @@ -0,0 +1,39 @@ +# Ansible Role: scheduled_tasks + +## Description + +You can specify a list of Schedules Tasks to be created under Windows. + +## Role Variables + +### scheduled_tasks + +List of Schedules Tasks, the single parameters can be taken from the [documentation](https://docs.ansible.com/ansible/latest/modules/win_scheduled_task_module.html) of Ansible. + +#### Example + +```yml +scheduled_tasks: + - name: 'Chocolatey Packages upgrade' + description: 'chocolatey upgrade all Packages evry Day at 12:00' + actions: + - path: powershell.exe + working_directory: 'C:\Support\scripts\' + arguments: '-ExecutionPolicy Bypass -File "C:\Support\scripts\Choco-Update.ps1"' + triggers: + - type: daily + start_boundary: '2017-10-09T12:00:00' + username: SYSTEM + state: present + enabled: true +``` + +## Example Playbook + +```yml +- hosts: all + collections: + - sbaerlocher.windows + roles: + - scheduled_tasks +``` diff --git a/roles/scheduled_tasks/defaults/main.yml b/roles/scheduled_tasks/defaults/main.yml new file mode 100644 index 0000000..62c0e54 --- /dev/null +++ b/roles/scheduled_tasks/defaults/main.yml @@ -0,0 +1,25 @@ +--- +# defaults file for scheduled_tasks + +# List of Schedules Tasks, the single parameters +# can be taken from the documentation of Ansible. +# https://docs.ansible.com/ansible/latest/modules/win_scheduled_task_module.html +# +# Example: +# +# scheduled_tasks: +# - name: 'Chocolatey Packages upgrade' +# description: 'chocolatey upgrade all Packages evry Day at 12:00' +# actions: +# - path: powershell.exe +# working_directory: 'C:\Support\scripts\' +# arguments: '-ExecutionPolicy Bypass -File "C:\Support\scripts\Choco-Update.ps1"' +# triggers: +# - type: daily +# start_boundary: '2017-10-09T12:00:00' +# username: SYSTEM +# state: present +# enabled: true +# + +# scheduled_tasks: diff --git a/roles/scheduled_tasks/meta/main.yml b/roles/scheduled_tasks/meta/main.yml new file mode 100644 index 0000000..b51b987 --- /dev/null +++ b/roles/scheduled_tasks/meta/main.yml @@ -0,0 +1,16 @@ +--- +galaxy_info: + author: Simon Baerlocher (https://sbaerlocher.ch) + description: Create scheduled tasks. + license: MIT + min_ansible_version: 2.9 + platforms: + - name: Windows + versions: + - all + + galaxy_tags: + - windows + - scheduled_tasks + +dependencies: [] diff --git a/roles/scheduled_tasks/molecule/default/molecule.yml b/roles/scheduled_tasks/molecule/default/molecule.yml new file mode 100644 index 0000000..265a5ef --- /dev/null +++ b/roles/scheduled_tasks/molecule/default/molecule.yml @@ -0,0 +1,21 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: instance + image: 'geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest' + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +scenario: + name: default +verifier: + name: testinfra + lint: + name: flake8 diff --git a/roles/scheduled_tasks/molecule/default/playbook.yml b/roles/scheduled_tasks/molecule/default/playbook.yml new file mode 100644 index 0000000..eee6e49 --- /dev/null +++ b/roles/scheduled_tasks/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: sbaerlocher.windows.scheduled_tasks diff --git a/roles/scheduled_tasks/tasks/main.yml b/roles/scheduled_tasks/tasks/main.yml new file mode 100644 index 0000000..6430722 --- /dev/null +++ b/roles/scheduled_tasks/tasks/main.yml @@ -0,0 +1,10 @@ +--- +# tasks file for scheduled_tasks + +- name: 'include scheduled tasks' + include_tasks: 'scheduled_task.yml' + loop: '{{ scheduled_tasks }}' + loop_control: + loop_var: scheduled_task + tags: + - configuration diff --git a/roles/scheduled_tasks/tasks/scheduled_task.yml b/roles/scheduled_tasks/tasks/scheduled_task.yml new file mode 100644 index 0000000..68b559a --- /dev/null +++ b/roles/scheduled_tasks/tasks/scheduled_task.yml @@ -0,0 +1,38 @@ +--- +# tasks file for scheduled_tasks + +- name: 'Create {{ scheduled_task.name }} scheduled task' + win_scheduled_task: + name: '{{ scheduled_task.name }}' + description: '{{ scheduled_task.description | default(omit) }}' + actions: '{{ scheduled_task.actions }}' + allow_demand_start: '{{ scheduled_task.allow_demand_start | default(omit) }}' + allow_hard_terminate: '{{ scheduled_task.allow_hard_terminate | default(omit) }}' + author: '{{ scheduled_task.author | default(omit) }}' + compatibility: '{{ scheduled_task.compatibility | default(omit) }}' + date: '{{ scheduled_task.date | default(omit) }}' + delete_expired_task_after: '{{ scheduled_task.delete_expired_task_after | default(omit) }}' + disallow_start_if_on_batteries: '{{ scheduled_task.disallow_start_if_on_batteries | default(omit) }}' + display_name: '{{ scheduled_task.display_name | default(omit) }}' + enabled: '{{ scheduled_task.enabled | default(omit) }}' + execution_time_limit: '{{ scheduled_task.execution_time_limit | default(omit) }}' + group: '{{ scheduled_task.group | default(omit) }}' + hidden: '{{ scheduled_task.delete_expired_task_after | default(omit) }}' + logon_type: '{{ scheduled_task.logon_type | default(omit) }}' + multiple_instances: '{{ scheduled_task.multiple_instances | default(omit) }}' + password: '{{ scheduled_task.password| default(omit) }}' + path: '{{ scheduled_task.path | default(omit) }}' + priority: '{{ scheduled_task.priority | default(omit) }}' + restart_count: '{{ scheduled_task.restart_count | default(omit) }}' + run_level: '{{ scheduled_task.run_level | default(omit) }}' + run_only_if_idle: '{{ scheduled_task.run_only_if_idle | default(omit) }}' + run_only_if_network_available: '{{ scheduled_task.run_only_if_network_available | default(omit) }}' + source: '{{ scheduled_task.source | default(omit) }}' + start_when_available: '{{ scheduled_task.start_when_available | default(omit) }}' + state: '{{ scheduled_task.state | default(omit) }}' + stop_if_going_on_batteries: '{{ scheduled_task.stop_if_going_on_batteries | default(omit) }}' + triggers: '{{ scheduled_task.triggers | default(omit) }}' + update_password: '{{ scheduled_task.update_password | default(omit) }}' + username: '{{ scheduled_task.username | default(omit) }}' + version: '{{ scheduled_task.version | default(omit) }}' + wake_to_run: '{{ scheduled_task.wake_to_run | default(omit) }}' From de22ec9c67cb2f1b58bc58fe661526c88c5b3714 Mon Sep 17 00:00:00 2001 From: Simon Baerlocher Date: Fri, 8 May 2020 16:13:18 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 6 ++++++ galaxy.yml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e45c76..4138fbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ and [human-readable changelog](https://keepachangelog.com/en/1.0.0/). ## master +## 0.0.4 + +### Added + +- Add role scheduled_tasks + ## 0.0.3 ### Fixed diff --git a/galaxy.yml b/galaxy.yml index dd067f3..5234cca 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: 'sbaerlocher' name: 'windows' -version: 0.0.3 +version: 0.0.4 readme: README.md authors: - 'Simon Baerlocher (https://sbaerlocher.ch)'