From 357a44803c6c92dc7c7c997af1df4e2e0517029e Mon Sep 17 00:00:00 2001 From: Drazen Date: Thu, 4 Sep 2025 08:42:08 +0200 Subject: [PATCH 1/2] Fixing-cron-syntax --- roles/cron/cron_drupal7/defaults/main.yml | 12 ++++++++++++ roles/cron/cron_drupal7/tasks/job.yml | 2 +- roles/cron/cron_drupal8/defaults/main.yml | 19 ++++++++++++++++--- roles/cron/cron_drupal8/tasks/job.yml | 2 +- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/roles/cron/cron_drupal7/defaults/main.yml b/roles/cron/cron_drupal7/defaults/main.yml index 636557ca..27e8caeb 100644 --- a/roles/cron/cron_drupal7/defaults/main.yml +++ b/roles/cron/cron_drupal7/defaults/main.yml @@ -19,3 +19,15 @@ drupal: # If defer is set to true, the Ansible target must be declared with defer_target. If using a group, include the index. For example, _ce_www_dev[0] defer_target: "" drush_location: "{{ drush_bin }}" # you might specify another location, e.g. "{{ deploy_path }}/vendor/bin/drush" + cron_error_filter: > + > /tmp/cron_output.txt 2>&1; rc=$?; + if [ $rc -ne 0 ]; then + mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; + elif grep -iE "(error|fail|fatal|critical|exception)" /tmp/cron_output.txt | grep -v -E '("rc": -13|MODULE FAILURE)' | grep -q .; then + mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; + fi + cron_error_email: >- + {% if entry.cron_error_mailto is defined %} + echo 'Command failed' | mail -s 'Cron Error - {{ inventory_hostname }}' {{ entry.cron_error_mailto }} + {% endif %} + python_interpreter: "-e 'ansible_python_interpreter=/home/controller/ce-python/bin/python'" diff --git a/roles/cron/cron_drupal7/tasks/job.yml b/roles/cron/cron_drupal7/tasks/job.yml index 18722640..2c442876 100644 --- a/roles/cron/cron_drupal7/tasks/job.yml +++ b/roles/cron/cron_drupal7/tasks/job.yml @@ -1,7 +1,7 @@ --- - name: Define cron job command. ansible.builtin.set_fact: - _cron_job_command: "cd {{ live_symlink_dest }}/{{ webroot }}/sites/{{ site.folder }} && {{ drupal.drush_location }} {{ entry.job }}" + _cron_job_command: "cd {{ _ce_deploy_base_dir }} && {{ _ce_deploy_ansible_location }} {{ drupal.defer_target }} {{ drupal.python_interpreter }} -m shell -a '{{ _cron_job_command }} {{ drupal.cron_error_filter }} {{ drupal.cron_error_email | default('') }}'" - name: Define cron job command if deferred (ASG). ansible.builtin.set_fact: diff --git a/roles/cron/cron_drupal8/defaults/main.yml b/roles/cron/cron_drupal8/defaults/main.yml index c49ed529..84324f60 100644 --- a/roles/cron/cron_drupal8/defaults/main.yml +++ b/roles/cron/cron_drupal8/defaults/main.yml @@ -12,12 +12,25 @@ drupal: # month: job: cron # disabled: true - # mailto: "{{ drupal.cron_mailto | default('') }}" # Each cron can have it's own mailto and can be configured to use different e-mail addresses. - # file: "/etc/cron.d/{{ project_name }}_{{ build_type }}_job_name" # edit job_name and uncomment to create a file for cron - note, deploy user needs to be able to write to the location - # file_user: "{{ deploy_user }}" # if you drop a file you must also supply an owner, usually the deploy user - make sure the deploy user has perms! + # mailto: "{{ drupal.cron_mailto | default('') }}" + # file: "/etc/cron.d/{{ project_name }}_{{ build_type }}_job_name" + # file_user: "{{ deploy_user }}" + cron_mailto: "" # If the sites are being deployed to an ASG, setting defer to true will create the crontab entry on the deploy server rather than all of the app servers. defer: false # If defer is set to true, the Ansible target must be declared with defer_target. If using a group, include the index. For example, _ce_www_dev[0] defer_target: "" drush_location: "{{ drush_bin }}" # you might specify another location, e.g. "{{ deploy_path }}/vendor/bin/drush" + cron_error_filter: > + > /tmp/cron_output.txt 2>&1; rc=$?; + if [ $rc -ne 0 ]; then + mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; + elif grep -iE "(error|fail|fatal|critical|exception)" /tmp/cron_output.txt | grep -v -E '("rc": -13|MODULE FAILURE)' | grep -q .; then + mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; + fi + cron_error_email: >- + {% if entry.cron_error_mailto is defined %} + echo 'Command failed' | mail -s 'Cron Error - {{ inventory_hostname }}' {{ entry.cron_error_mailto }} + {% endif %} + python_interpreter: "-e 'ansible_python_interpreter=/home/controller/ce-python/bin/python'" diff --git a/roles/cron/cron_drupal8/tasks/job.yml b/roles/cron/cron_drupal8/tasks/job.yml index 9c039fdc..386065c7 100644 --- a/roles/cron/cron_drupal8/tasks/job.yml +++ b/roles/cron/cron_drupal8/tasks/job.yml @@ -5,7 +5,7 @@ - name: Define cron job command if deferred (ASG). ansible.builtin.set_fact: - _cron_job_command: "cd {{ _ce_deploy_base_dir }} && {{ _ce_deploy_ansible_location }} {{ drupal.defer_target }} -m shell -a \"{{ _cron_job_command }}\" > /dev/null" + _cron_job_command: "cd {{ _ce_deploy_base_dir }} && {{ _ce_deploy_ansible_location }} {{ drupal.defer_target }} {{ drupal.python_interpreter }} -m shell -a '{{ _cron_job_command }} {{ drupal.cron_error_filter }} {{ drupal.cron_error_email | default('') }}'" when: - drupal.defer is defined - drupal.defer From e4729b7a3a2935da2d8011c005a6e68d88bb1cde Mon Sep 17 00:00:00 2001 From: Drazen Date: Thu, 4 Sep 2025 09:51:14 +0200 Subject: [PATCH 2/2] Fixing-cron-syntax-PR-1.x --- roles/cron/cron_drupal7/defaults/main.yml | 13 ++----------- roles/cron/cron_drupal7/tasks/job.yml | 2 +- roles/cron/cron_drupal8/defaults/main.yml | 13 ++----------- 3 files changed, 5 insertions(+), 23 deletions(-) diff --git a/roles/cron/cron_drupal7/defaults/main.yml b/roles/cron/cron_drupal7/defaults/main.yml index 27e8caeb..e066b6e7 100644 --- a/roles/cron/cron_drupal7/defaults/main.yml +++ b/roles/cron/cron_drupal7/defaults/main.yml @@ -19,15 +19,6 @@ drupal: # If defer is set to true, the Ansible target must be declared with defer_target. If using a group, include the index. For example, _ce_www_dev[0] defer_target: "" drush_location: "{{ drush_bin }}" # you might specify another location, e.g. "{{ deploy_path }}/vendor/bin/drush" - cron_error_filter: > - > /tmp/cron_output.txt 2>&1; rc=$?; - if [ $rc -ne 0 ]; then - mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; - elif grep -iE "(error|fail|fatal|critical|exception)" /tmp/cron_output.txt | grep -v -E '("rc": -13|MODULE FAILURE)' | grep -q .; then - mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; - fi - cron_error_email: >- - {% if entry.cron_error_mailto is defined %} - echo 'Command failed' | mail -s 'Cron Error - {{ inventory_hostname }}' {{ entry.cron_error_mailto }} - {% endif %} + cron_error_filter: "> /tmp/cron_output.txt 2>&1; rc=$?; if [ $rc -ne 0 ]; then mail -s \"Cron Error - $(hostname)\" sysadm@codeenigma.com < /tmp/cron_output.txt; elif grep -iE \"(error|fail|fatal|critical|exception)\" /tmp/cron_output.txt | grep -v -E '(\"rc\": -13|MODULE FAILURE)' | grep -q .; then mail -s \"Cron Error - $(hostname)\" sysadm@codeenigma.com < /tmp/cron_output.txt; fi" + cron_error_email: "{% if entry.cron_error_mailto is defined %}; if [ $rc -ne 0 ] || grep -iE \"(error|fail|fatal|critical|exception)\" /tmp/cron_output.txt | grep -v -E '(\"rc\": -13|MODULE FAILURE)' | grep -q .; then echo 'Command failed' | mail -s 'Cron Error - {{ inventory_hostname }}' {{ entry.cron_error_mailto }}; fi{% endif %}" python_interpreter: "-e 'ansible_python_interpreter=/home/controller/ce-python/bin/python'" diff --git a/roles/cron/cron_drupal7/tasks/job.yml b/roles/cron/cron_drupal7/tasks/job.yml index 2c442876..18722640 100644 --- a/roles/cron/cron_drupal7/tasks/job.yml +++ b/roles/cron/cron_drupal7/tasks/job.yml @@ -1,7 +1,7 @@ --- - name: Define cron job command. ansible.builtin.set_fact: - _cron_job_command: "cd {{ _ce_deploy_base_dir }} && {{ _ce_deploy_ansible_location }} {{ drupal.defer_target }} {{ drupal.python_interpreter }} -m shell -a '{{ _cron_job_command }} {{ drupal.cron_error_filter }} {{ drupal.cron_error_email | default('') }}'" + _cron_job_command: "cd {{ live_symlink_dest }}/{{ webroot }}/sites/{{ site.folder }} && {{ drupal.drush_location }} {{ entry.job }}" - name: Define cron job command if deferred (ASG). ansible.builtin.set_fact: diff --git a/roles/cron/cron_drupal8/defaults/main.yml b/roles/cron/cron_drupal8/defaults/main.yml index 84324f60..e74a6ca2 100644 --- a/roles/cron/cron_drupal8/defaults/main.yml +++ b/roles/cron/cron_drupal8/defaults/main.yml @@ -22,15 +22,6 @@ drupal: # If defer is set to true, the Ansible target must be declared with defer_target. If using a group, include the index. For example, _ce_www_dev[0] defer_target: "" drush_location: "{{ drush_bin }}" # you might specify another location, e.g. "{{ deploy_path }}/vendor/bin/drush" - cron_error_filter: > - > /tmp/cron_output.txt 2>&1; rc=$?; - if [ $rc -ne 0 ]; then - mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; - elif grep -iE "(error|fail|fatal|critical|exception)" /tmp/cron_output.txt | grep -v -E '("rc": -13|MODULE FAILURE)' | grep -q .; then - mail -s "Cron Error - $(hostname)" sysadm@codeenigma.com < /tmp/cron_output.txt; - fi - cron_error_email: >- - {% if entry.cron_error_mailto is defined %} - echo 'Command failed' | mail -s 'Cron Error - {{ inventory_hostname }}' {{ entry.cron_error_mailto }} - {% endif %} + cron_error_filter: "> /tmp/cron_output.txt 2>&1; rc=$?; if [ $rc -ne 0 ]; then mail -s \"Cron Error - $(hostname)\" sysadm@codeenigma.com < /tmp/cron_output.txt; elif grep -iE \"(error|fail|fatal|critical|exception)\" /tmp/cron_output.txt | grep -v -E '(\"rc\": -13|MODULE FAILURE)' | grep -q .; then mail -s \"Cron Error - $(hostname)\" sysadm@codeenigma.com < /tmp/cron_output.txt; fi" + cron_error_email: "{% if entry.cron_error_mailto is defined %}; if [ $rc -ne 0 ] || grep -iE \"(error|fail|fatal|critical|exception)\" /tmp/cron_output.txt | grep -v -E '(\"rc\": -13|MODULE FAILURE)' | grep -q .; then echo 'Command failed' | mail -s 'Cron Error - {{ inventory_hostname }}' {{ entry.cron_error_mailto }}; fi{% endif %}" python_interpreter: "-e 'ansible_python_interpreter=/home/controller/ce-python/bin/python'"