Commit e20aa7d6 authored by Eric Zillmann's avatar Eric Zillmann
Browse files

ansible-inventories/arocom#2838 added script and tasks for "crontabs_collector"

parent a57217ae
---
# file: roles/drupal/tasks/crontabs_collector.yml
- block:
- name: Install crontabs collector
template:
src: scripts/config/crontabs_collector.php.jinja2
dest: /usr/local/bin/crontabs_collector.php
owner: root
group: root
mode: 0775
tags:
- crontabs_collector
......@@ -42,6 +42,11 @@
tags:
- haproxy_redirects_collector
- name: Install crontabs collector
include_tasks: crontabs_collector.yml
tags:
- crontabs_collector
when: (not excluded_roles or "drupal" not in excluded_roles) and drupal_install_drupal and (collect_config is not defined or not collect_config)
- block:
......
#!/usr/bin/php
<?php
// Define input and output files.
// Production files.
$input_files_definitions = [];
{% for drupal in drupal_settings|default([]) %}
{% if drupal.src.git.target2 is defined %}
$input_files_definitions[] = '{{ jailroot }}/{{ drupal.jail.name }}/var/www{{ drupal.webRoot|default("") }}{{ drupal.src.git.target2 }}/crons/*.json';
{% endif %}
{% endfor %}
$output_file = '/etc/ansible/facts.d/crontabs.fact';
// Get the input file listing.
$input_files = [];
foreach ($input_files_definitions as $input_files_definition) {
$input_files_tmp = glob($input_files_definition);
if (!is_array($input_files_tmp)) {
continue;
}
$input_files = array_merge($input_files, $input_files_tmp);
}
// Resulting crontab definition list.
$crontab_definitions = [];
// Walk over the input files and merge each one to the result.
foreach ($input_files as $input_file) {
// Read the raw file contents.
$input_file_content = @file_get_contents($input_file);
// JSON decode the file contents.
$input_file_decoded = @json_decode($input_file_content, true);
// Make sure we have a valid list.
if (!is_array($input_file_decoded)) {
continue;
}
// Merge the decoded file contents to the result.
$crontab_definitions = array_merge($crontab_definitions, $input_file_decoded);
}
// JSON encode the result.
$crontab_content = json_encode($crontab_definitions);
// Write the JSON encoded result to the output file.
file_put_contents($output_file, $crontab_content);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment