From 7bd875e21e8afc2a72ee0abe4b9872fd7e3a4546 Mon Sep 17 00:00:00 2001 From: AnsibleRoles <> Date: Sun, 22 Nov 2020 13:28:27 -0600 Subject: [PATCH 01/17] Initial commit --- .gitignore | 433 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 + 2 files changed, 435 insertions(+) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..af67746 --- /dev/null +++ b/.gitignore @@ -0,0 +1,433 @@ +# ---> Ansible +*.retry + +# ---> Windows +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# ---> macOS +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# ---> Linux +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +# ---> Vim +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim + +# Temporary +.netrwhist +*~ +# Auto-generated tag files +tags +# Persistent undo +[._]*.un~ + +# ---> VisualStudio +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# ---> VisualStudioCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d7738ea --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# ensure_timezone + From 7d88e699bf5fed78fa5d6242727517dc44d05198 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 22 Nov 2020 14:41:50 -0600 Subject: [PATCH 02/17] Configure timezones, defaulting to UTC --- .travis.yml | 29 +++++++++++++++++++ README.md | 38 +++++++++++++++++++++++- defaults/main.yml | 5 ++++ handlers/main.yml | 7 +++++ meta/main.yml | 53 ++++++++++++++++++++++++++++++++++ tasks/main.yml | 73 +++++++++++++++++++++++++++++++++++++++++++++++ tests/inventory | 2 ++ tests/test.yml | 5 ++++ vars/main.yml | 2 ++ 9 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 vars/main.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/README.md b/README.md index d7738ea..225dd44 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,38 @@ -# ensure_timezone +Role Name +========= +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..1f2ff4b --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,5 @@ +--- +# defaults file for ensure_timezone +timezone: + hwclock: 'UTC' + name: 'UTC' diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..e50b290 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,7 @@ +--- +# handlers file for ensure_timezone +- name: 'ensure_timezone.package_facts' + ansible.builtin.package_facts: +- name: 'ensure_timezone.service_facts' + ansible.builtin.service_facts: + diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..b7af6b5 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: Jason Rothstein + description: Ensure time zone is configured, and cron restarted if there is a change + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.9 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..43b165f --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,73 @@ +--- +# tasks file for ensure_timezone +- name: 'package discovery' + when: + - ansible_system == 'Linux' + - packages is not defined + ansible.builtin.package_facts: +- name: 'service discovery' + when: + - ansible_system == 'Linux' + - services is not defined + ansible.builtin.package_facts: +- name: 'flush handlers' + ansible.builtin.meta: 'flush_handlers' +- name: 'Set timezone' + community.general.timezone: + hwclock: '{{ timezone.hwclock }}' + name: '{{ timezone.name }}' + register: 'results' +- name: 'Restart cron if TZ changed' + notify: + - 'service_facts' + when: + - services is defined + - services['crond.service'] is defined + - results.diff.before != results.diff.after + service: + name: 'crond.service' + state: 'restarted' +- name: 'Restart if time zone changed' + when: + - ansible_system == 'Linux' + - services is defined + - services[item.name] is defined + ansible.builtin.service: + enabled: '{{ item.enabled }}' + name: '{{ item.name }}' + state: '{{ item.state }}' + loop: + - enabled: 'yes' + name: 'crond' + state: 'restarted' + - enabled: 'yes' + name: 'crond.service' + state: 'restarted' + loop_control: + label: '{{ item.name }} will be {{ item.state }}' + notify: + - 'ensure_timezone.package_facts' + - 'ensure_timezone.service_facts' +- name: 'ensure services' + when: + - ansible_system == 'Linux' + - services is defined + - services[item.name] is defined + ansible.builtin.service: + enabled: '{{ item.enabled }}' + name: '{{ item.name }}' + state: '{{ item.state }}' + loop: + - enabled: 'yes' + name: 'crond' + state: 'started' + - enabled: 'yes' + name: 'crond.service' + state: 'started' + loop_control: + label: '{{ item.name }} will be {{ item.state }}' + notify: + - 'ensure_timezone.package_facts' + - 'ensure_timezone.service_facts' +- name: 'flush handlers' + meta: 'flush_handlers' diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..917a267 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - ensure_timezone \ No newline at end of file diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..7c16b44 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for ensure_timezone \ No newline at end of file From c85dd54dedf4ed3193e96eb743cd5c57ef826569 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 22 Nov 2020 15:58:37 -0600 Subject: [PATCH 03/17] Ansible doesn't like FQCN on meta?! --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 43b165f..e2d2371 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,7 +11,7 @@ - services is not defined ansible.builtin.package_facts: - name: 'flush handlers' - ansible.builtin.meta: 'flush_handlers' + meta: 'flush_handlers' - name: 'Set timezone' community.general.timezone: hwclock: '{{ timezone.hwclock }}' From 0893312567d7e6ccc6c059bfa5c953293b471d3a Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 22 Nov 2020 16:11:44 -0600 Subject: [PATCH 04/17] Remove duplicate service restart code --- tasks/main.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index e2d2371..bbfc8ff 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -17,16 +17,6 @@ hwclock: '{{ timezone.hwclock }}' name: '{{ timezone.name }}' register: 'results' -- name: 'Restart cron if TZ changed' - notify: - - 'service_facts' - when: - - services is defined - - services['crond.service'] is defined - - results.diff.before != results.diff.after - service: - name: 'crond.service' - state: 'restarted' - name: 'Restart if time zone changed' when: - ansible_system == 'Linux' @@ -71,3 +61,4 @@ - 'ensure_timezone.service_facts' - name: 'flush handlers' meta: 'flush_handlers' + From 4fc9faa2d6e6797cfac74a0fd1ab6ed6dc412000 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 29 Nov 2020 21:27:46 -0600 Subject: [PATCH 05/17] Document and ensure Ansible FQCN --- README.md | 8 +++++--- meta/main.yml | 2 +- tasks/main.yml | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 225dd44..285ac7e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ Role Name ========= -A brief description of the role goes here. +Ensure the OS time zone is defined Requirements ------------ -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +Please ensure the following collections are installed : + +* community.general Role Variables -------------- @@ -30,7 +32,7 @@ Including an example of how to use your role (for instance, with variables passe License ------- -BSD +LGPL-3.0-or-later Author Information ------------------ diff --git a/meta/main.yml b/meta/main.yml index b7af6b5..b8d6c36 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -14,7 +14,7 @@ galaxy_info: # - GPL-3.0-only # - Apache-2.0 # - CC-BY-4.0 - license: license (GPL-2.0-or-later, MIT, etc) + license: LGPL-3.0-or-later min_ansible_version: 2.9 diff --git a/tasks/main.yml b/tasks/main.yml index bbfc8ff..43a265c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -10,8 +10,6 @@ - ansible_system == 'Linux' - services is not defined ansible.builtin.package_facts: -- name: 'flush handlers' - meta: 'flush_handlers' - name: 'Set timezone' community.general.timezone: hwclock: '{{ timezone.hwclock }}' From 86c66a7632266be2b9c4e1a637d0509453986ebb Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 29 Nov 2020 23:54:27 -0600 Subject: [PATCH 06/17] Only restart cron if time zone actually changed... --- tasks/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks/main.yml b/tasks/main.yml index 43a265c..cf81396 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,6 +20,7 @@ - ansible_system == 'Linux' - services is defined - services[item.name] is defined + - results.changed ansible.builtin.service: enabled: '{{ item.enabled }}' name: '{{ item.name }}' From 0962e8f74b5e5a90f20aee80da1a9d1653150b2f Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 6 Dec 2020 00:44:26 -0600 Subject: [PATCH 07/17] Enable override of timezone name or hwclock independently --- defaults/main.yml | 6 +++--- tasks/main.yml | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 1f2ff4b..4504986 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,5 +1,5 @@ --- # defaults file for ensure_timezone -timezone: - hwclock: 'UTC' - name: 'UTC' +timezone_hwclock: 'UTC' +timezone_name: 'UTC' + diff --git a/tasks/main.yml b/tasks/main.yml index cf81396..cba813d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,8 +12,8 @@ ansible.builtin.package_facts: - name: 'Set timezone' community.general.timezone: - hwclock: '{{ timezone.hwclock }}' - name: '{{ timezone.name }}' + hwclock: '{{ timezone_hwclock }}' + name: '{{ timezone_name }}' register: 'results' - name: 'Restart if time zone changed' when: From 18a956539000bc5f2aad57db2f1ce568e12375fb Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 20 Dec 2020 07:45:25 -0600 Subject: [PATCH 08/17] Do service discovery as well as package discovery --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index cba813d..e88c841 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,7 +9,7 @@ when: - ansible_system == 'Linux' - services is not defined - ansible.builtin.package_facts: + ansible.builtin.service_facts: - name: 'Set timezone' community.general.timezone: hwclock: '{{ timezone_hwclock }}' From bac97012c0259564f6dd433104883f628d038e38 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 5 Jun 2022 16:30:22 -0500 Subject: [PATCH 09/17] Update handlers --- handlers/main.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/handlers/main.yml b/handlers/main.yml index e50b290..8917f51 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -4,4 +4,24 @@ ansible.builtin.package_facts: - name: 'ensure_timezone.service_facts' ansible.builtin.service_facts: - +- name: 'ensure_timezone.service_reload' + when: + - ansible_system == 'Linux' + - ansible_service_mgr == 'systemd' + - ensure_timezone is defined + ansible.builtin.systemd: + daemon_reload: 'yes' +- name: 'ensure_timezone.services' + when: + - ansible_system == 'Linux' + - ensure_timezone is defined + - ensure_timezone.service_list is defined + - ensure_timezone.service_list is iterable + - item.state == 'started' + ansible.builtin.service: + enabled: '{{ item.enabled }}' + name: '{{ item.name }}' + state: 'restarted' + loop: '{{ ensure_timezone.service_list }}' + loop_control: + label: '{{ item.name }} will be restarted' From f2d38a6b3ca8f4872fec78ac15c930a81bd665e8 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 5 Jun 2022 16:48:50 -0500 Subject: [PATCH 10/17] Update tasks --- tasks/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index e88c841..e6099db 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -60,4 +60,3 @@ - 'ensure_timezone.service_facts' - name: 'flush handlers' meta: 'flush_handlers' - From f35e3052a2295576f7729fd99e2dca56cb886033 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Sun, 25 May 2025 20:14:21 -0500 Subject: [PATCH 11/17] Handler Improvements Signed-off-by: Jason Rothstein --- handlers/main.yml | 4 +++- tasks/main.yml | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/handlers/main.yml b/handlers/main.yml index 8917f51..39699b4 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -11,7 +11,7 @@ - ensure_timezone is defined ansible.builtin.systemd: daemon_reload: 'yes' -- name: 'ensure_timezone.services' +- name: 'ensure_timezone.service_restart' when: - ansible_system == 'Linux' - ensure_timezone is defined @@ -25,3 +25,5 @@ loop: '{{ ensure_timezone.service_list }}' loop_control: label: '{{ item.name }} will be restarted' +... + diff --git a/tasks/main.yml b/tasks/main.yml index e6099db..9ec2511 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -60,3 +60,5 @@ - 'ensure_timezone.service_facts' - name: 'flush handlers' meta: 'flush_handlers' +... + From 061fcdfe0b214f74eb3afbab57ba421aacf2bdb4 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Tue, 5 May 2026 14:19:45 -0500 Subject: [PATCH 12/17] Fix ansible core 2.20 Signed-off-by: Jason Rothstein --- tasks/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 9ec2511..1f5f303 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -2,12 +2,12 @@ # tasks file for ensure_timezone - name: 'package discovery' when: - - ansible_system == 'Linux' - - packages is not defined + - ansible_facts["system"] == 'Linux' + - ansible_facts["packages"] is not defined ansible.builtin.package_facts: - name: 'service discovery' when: - - ansible_system == 'Linux' + - ansible_facts["system"] == 'Linux' - services is not defined ansible.builtin.service_facts: - name: 'Set timezone' @@ -17,7 +17,7 @@ register: 'results' - name: 'Restart if time zone changed' when: - - ansible_system == 'Linux' + - ansible_facts["system"] == 'Linux' - services is defined - services[item.name] is defined - results.changed @@ -39,7 +39,7 @@ - 'ensure_timezone.service_facts' - name: 'ensure services' when: - - ansible_system == 'Linux' + - ansible_facts["system"] == 'Linux' - services is defined - services[item.name] is defined ansible.builtin.service: From 819b4cc4f9e7aff30a01f34ac95332884183374e Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Tue, 5 May 2026 17:10:29 -0500 Subject: [PATCH 13/17] More ansible core 2.20 fixes Signed-off-by: Jason Rothstein --- handlers/main.yml | 6 +++--- tasks/main.yml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 39699b4..f69d338 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -6,14 +6,14 @@ ansible.builtin.service_facts: - name: 'ensure_timezone.service_reload' when: - - ansible_system == 'Linux' - - ansible_service_mgr == 'systemd' + - ansible_facts["system"] == 'Linux' + - ansible_facts["service_mgr"] == 'systemd' - ensure_timezone is defined ansible.builtin.systemd: daemon_reload: 'yes' - name: 'ensure_timezone.service_restart' when: - - ansible_system == 'Linux' + - ansible_facts["system"] == 'Linux' - ensure_timezone is defined - ensure_timezone.service_list is defined - ensure_timezone.service_list is iterable diff --git a/tasks/main.yml b/tasks/main.yml index 1f5f303..8f4f488 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,7 +8,7 @@ - name: 'service discovery' when: - ansible_facts["system"] == 'Linux' - - services is not defined + - ansible_facts["services"] is not defined ansible.builtin.service_facts: - name: 'Set timezone' community.general.timezone: From c52da7c031e5c8441ca3636b72e9eaa4e7f4bd4e Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Tue, 5 May 2026 17:25:32 -0500 Subject: [PATCH 14/17] Rewrite to act like rest of roles, add common OS list Signed-off-by: Jason Rothstein --- tasks/main.yml | 114 +++++++++++++++++++++++++------- vars/AlmaLinux-10-default.yml | 8 +++ vars/AlmaLinux-8-default.yml | 8 +++ vars/AlmaLinux-9-default.yml | 8 +++ vars/CentOS-10-default.yml | 8 +++ vars/CentOS-8-default.yml | 8 +++ vars/CentOS-9-default.yml | 8 +++ vars/Debian-11-default.yml | 8 +++ vars/Debian-12-default.yml | 8 +++ vars/Debian-13-default.yml | 8 +++ vars/Fedora-42-default.yml | 8 +++ vars/Fedora-43-default.yml | 8 +++ vars/Fedora-44-default.yml | 8 +++ vars/OracleLinux-10-default.yml | 8 +++ vars/OracleLinux-8-default.yml | 8 +++ vars/OracleLinux-9-default.yml | 8 +++ vars/Rocky-10-default.yml | 8 +++ vars/Rocky-8-default.yml | 8 +++ vars/Rocky-9-default.yml | 8 +++ vars/Ubuntu-26-default.yml | 8 +++ 20 files changed, 243 insertions(+), 23 deletions(-) create mode 100644 vars/AlmaLinux-10-default.yml create mode 100644 vars/AlmaLinux-8-default.yml create mode 100644 vars/AlmaLinux-9-default.yml create mode 100644 vars/CentOS-10-default.yml create mode 100644 vars/CentOS-8-default.yml create mode 100644 vars/CentOS-9-default.yml create mode 100644 vars/Debian-11-default.yml create mode 100644 vars/Debian-12-default.yml create mode 100644 vars/Debian-13-default.yml create mode 100644 vars/Fedora-42-default.yml create mode 100644 vars/Fedora-43-default.yml create mode 100644 vars/Fedora-44-default.yml create mode 100644 vars/OracleLinux-10-default.yml create mode 100644 vars/OracleLinux-8-default.yml create mode 100644 vars/OracleLinux-9-default.yml create mode 100644 vars/Rocky-10-default.yml create mode 100644 vars/Rocky-8-default.yml create mode 100644 vars/Rocky-9-default.yml create mode 100644 vars/Ubuntu-26-default.yml diff --git a/tasks/main.yml b/tasks/main.yml index 8f4f488..7b8791e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,5 +1,24 @@ --- # tasks file for ensure_timezone +- name: 'include variables' + when: + - ansible_facts["system"] == 'Linux' + include_vars: + file: '{{ lookup("first_found", findme ) }}' + name: 'ensure_timezone' + vars: + findme: + files: + - '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"] }}-{{ ansible_facts["architecture"] }}.yml' + - '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"] }}-default.yml' + - '{{ ansible_facts["distribution"] }}-default.yml' + - '{{ ansible_os_family }}-{{ ansible_facts["distribution_major_version"] }}-{{ ansible_facts["architecture"] }}.yml' + - '{{ ansible_os_family }}-{{ ansible_facts["distribution_major_version"] }}-default.yml' + - '{{ ansible_os_family }}-default.yml' + - 'default.yml' + paths: + - '../vars/' + errors: 'ignore' - name: 'package discovery' when: - ansible_facts["system"] == 'Linux' @@ -14,50 +33,99 @@ community.general.timezone: hwclock: '{{ timezone_hwclock }}' name: '{{ timezone_name }}' - register: 'results' -- name: 'Restart if time zone changed' + notify: + - 'ensure_timezone.package_facts' + - 'ensure_timezone.service_facts' + - 'ensure_timezone.service_restart' +- name: 'ensure packages' when: - ansible_facts["system"] == 'Linux' - - services is defined - - services[item.name] is defined - - results.changed - ansible.builtin.service: - enabled: '{{ item.enabled }}' + - ensure_timezone is defined + - ensure_timezone.package_list is defined + - ensure_timezone.package_list is iterable + ansible.builtin.package: name: '{{ item.name }}' state: '{{ item.state }}' - loop: - - enabled: 'yes' - name: 'crond' - state: 'restarted' - - enabled: 'yes' - name: 'crond.service' - state: 'restarted' + loop: '{{ ensure_timezone.package_list }}' loop_control: label: '{{ item.name }} will be {{ item.state }}' notify: - 'ensure_timezone.package_facts' - 'ensure_timezone.service_facts' +- name: 'ensure configurations' + when: + - ansible_facts["system"] == 'Linux' + - ensure_timezone is defined + - ensure_timezone.template_list is defined + - ensure_timezone.template_list is iterable + ansible.builtin.template: + backup: 'no' + dest: '{{ item.dest }}' + group: '{{ item.group | default(omit) }}' + mode: '{{ item.mode | default(omit) }}' + owner: '{{ item.owner | default(omit) }}' + selevel: '{{ iteml.selevel | default(omit) }}' + serole: '{{ item.serole | default(omit) }}' + setype: '{{ item.setype | default(omit) }}' + seuser: '{{ item.seuser | default(omit) }}' + src: '{{ item.src }}' + loop: '{{ ensure_timezone.template_list }}' + loop_control: + label: '{{ item.dest }} will be ensured' + notify: + - 'ensure_timezone.package_facts' + - 'ensure_timezone.service_facts' + - 'ensure_timezone.service_reload' + - 'ensure_timezone.service_restart' - name: 'ensure services' when: - ansible_facts["system"] == 'Linux' - - services is defined - - services[item.name] is defined + - ensure_timezone is defined + - ensure_timezone.service_list is defined + - ensure_timezone.service_list is iterable ansible.builtin.service: enabled: '{{ item.enabled }}' name: '{{ item.name }}' state: '{{ item.state }}' - loop: - - enabled: 'yes' - name: 'crond' - state: 'started' - - enabled: 'yes' - name: 'crond.service' - state: 'started' + loop: '{{ ensure_timezone.service_list }}' loop_control: label: '{{ item.name }} will be {{ item.state }}' notify: - 'ensure_timezone.package_facts' - 'ensure_timezone.service_facts' +- name: 'Ensure SELinux is configured' + when: + - ansible_facts["system"] == 'Linux' + - ensure_timezone is defined + - ensure_timezone.selinux_policy is defined + - ensure_timezone.selinux_state is defined + ansible.posix.selinux: + policy: '{{ ensure_timezone.selinux_policy }}' + state: '{{ ensure_timezone.selinux_state }}' + register: 'results' +- name: 'Reboot if required' + when: + - ansible_facts["system"] == 'Linux' + - ensure_timezone is defined + - ensure_timezone.selinux_policy is defined + - ensure_timezone.selinux_state is defined + - results is defined + - results.reboot_required is defined + - results.reboot_required + reboot: +- name: 'ensure seboolean' + when: + - ansible_facts["system"] == 'Linux' + - ensure_timezone is defined + - ensure_timezone.seboolean_list is defined + - ensure_timezone.seboolean_list is iterable + ansible.posix.seboolean: + name: '{{ item.name }}' + persistent: '{{ item.persistent }}' + state: '{{ item.state }}' + loop: '{{ ensure_timezone.seboolean_list }}' + loop_control: + label: '{{ item.name }} will be {{ item.state }}' - name: 'flush handlers' meta: 'flush_handlers' ... diff --git a/vars/AlmaLinux-10-default.yml b/vars/AlmaLinux-10-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/AlmaLinux-10-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/AlmaLinux-8-default.yml b/vars/AlmaLinux-8-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/AlmaLinux-8-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/AlmaLinux-9-default.yml b/vars/AlmaLinux-9-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/AlmaLinux-9-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/CentOS-10-default.yml b/vars/CentOS-10-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/CentOS-10-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/CentOS-8-default.yml b/vars/CentOS-8-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/CentOS-8-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/CentOS-9-default.yml b/vars/CentOS-9-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/CentOS-9-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/Debian-11-default.yml b/vars/Debian-11-default.yml new file mode 100644 index 0000000..bf9898b --- /dev/null +++ b/vars/Debian-11-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'cron.service' + state: 'started' +... + diff --git a/vars/Debian-12-default.yml b/vars/Debian-12-default.yml new file mode 100644 index 0000000..bf9898b --- /dev/null +++ b/vars/Debian-12-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'cron.service' + state: 'started' +... + diff --git a/vars/Debian-13-default.yml b/vars/Debian-13-default.yml new file mode 100644 index 0000000..bf9898b --- /dev/null +++ b/vars/Debian-13-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'cron.service' + state: 'started' +... + diff --git a/vars/Fedora-42-default.yml b/vars/Fedora-42-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/Fedora-42-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/Fedora-43-default.yml b/vars/Fedora-43-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/Fedora-43-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/Fedora-44-default.yml b/vars/Fedora-44-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/Fedora-44-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/OracleLinux-10-default.yml b/vars/OracleLinux-10-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/OracleLinux-10-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/OracleLinux-8-default.yml b/vars/OracleLinux-8-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/OracleLinux-8-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/OracleLinux-9-default.yml b/vars/OracleLinux-9-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/OracleLinux-9-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/Rocky-10-default.yml b/vars/Rocky-10-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/Rocky-10-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/Rocky-8-default.yml b/vars/Rocky-8-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/Rocky-8-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/Rocky-9-default.yml b/vars/Rocky-9-default.yml new file mode 100644 index 0000000..986a453 --- /dev/null +++ b/vars/Rocky-9-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'crond.service' + state: 'started' +... + diff --git a/vars/Ubuntu-26-default.yml b/vars/Ubuntu-26-default.yml new file mode 100644 index 0000000..bf9898b --- /dev/null +++ b/vars/Ubuntu-26-default.yml @@ -0,0 +1,8 @@ +--- +# vars file for ensure_timezone +service_list: + - enabled: 'yes' + name: 'cron.service' + state: 'started' +... + From d111b82dd13f8aeca6d28f6fe60fb1671f3a4d54 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Tue, 5 May 2026 18:18:19 -0500 Subject: [PATCH 15/17] More ansible 2.20 fixes Signed-off-by: Jason Rothstein --- tasks/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 7b8791e..48377de 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,9 +12,9 @@ - '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"] }}-{{ ansible_facts["architecture"] }}.yml' - '{{ ansible_facts["distribution"] }}-{{ ansible_facts["distribution_major_version"] }}-default.yml' - '{{ ansible_facts["distribution"] }}-default.yml' - - '{{ ansible_os_family }}-{{ ansible_facts["distribution_major_version"] }}-{{ ansible_facts["architecture"] }}.yml' - - '{{ ansible_os_family }}-{{ ansible_facts["distribution_major_version"] }}-default.yml' - - '{{ ansible_os_family }}-default.yml' + - '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"] }}-{{ ansible_facts["architecture"] }}.yml' + - '{{ ansible_facts["os_family"] }}-{{ ansible_facts["distribution_major_version"] }}-default.yml' + - '{{ ansible_facts["os_family"] }}-default.yml' - 'default.yml' paths: - '../vars/' From 0ef012d42f207cd73b61c6d69362a5aa3403bab1 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Tue, 5 May 2026 18:29:24 -0500 Subject: [PATCH 16/17] Add default variable file to handle the unknown Signed-off-by: Jason Rothstein --- vars/default.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 vars/default.yml diff --git a/vars/default.yml b/vars/default.yml new file mode 100644 index 0000000..7c16b44 --- /dev/null +++ b/vars/default.yml @@ -0,0 +1,2 @@ +--- +# vars file for ensure_timezone \ No newline at end of file From f60fb072a0b6c2bd2e933fc649d282eef458dec7 Mon Sep 17 00:00:00 2001 From: Jason Rothstein Date: Tue, 5 May 2026 19:38:04 -0500 Subject: [PATCH 17/17] Remove Ubuntu's cron.service that doesn't exist Signed-off-by: Jason Rothstein --- vars/Ubuntu-26-default.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 vars/Ubuntu-26-default.yml diff --git a/vars/Ubuntu-26-default.yml b/vars/Ubuntu-26-default.yml deleted file mode 100644 index bf9898b..0000000 --- a/vars/Ubuntu-26-default.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -# vars file for ensure_timezone -service_list: - - enabled: 'yes' - name: 'cron.service' - state: 'started' -... -