diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a1bf55..df0bc0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Enhancement * Upgrade package version from URL from 2.4 to 2.6 (thanks to @roumano - issue #15). +* Allow running the agent with a cron job instead of the service (thanks to @yodabzh - issue #18) ### Fix * Switch to Github URL to download deb file (thanks to @roumano - PR #16). diff --git a/README.md b/README.md index 3d29310..c11c9e6 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,17 @@ A role to manage FusionInventory agent installation and configuration. * **fusioninventory__agent_service_manage** : If the fusioninventory agent service should be managed [default : `true`]. * **fusioninventory__agent_conf_src** : Template used to provide agent configuration file [default : `../templates/etc/fusioninventory/agent.cfg.j2`]. +## Cron variables + +* **fusioninventory__agent_conf_cron**: Enable (`"present"`) or disable (`"absent"`) a job cron to run the agent [default : `"absent"`]. +* **fusioninventory__agent_conf_cron_day**: Which days should the agent be ran [default : `"*"`]. +* **fusioninventory__agent_conf_cron_hour**: Which hours should the agent be ran [default : `"23"`]. +* **fusioninventory__agent_conf_cron_minute**: Which minutes should the agent be ran [default : `"0"`]. +* **fusioninventory__agent_conf_cron_month**: Which months should the agent be ran [default : `"*"`]. +* **fusioninventory__agent_conf_cron_weekday**: Which weekdays should the agent be ran [default : `"*"`]. +* **fusioninventory__agent_conf_cron_user**: Which user should the agent be ran under [default : `"root"`]. +* **fusioninventory__agent_conf_command**: The command should cron run [default : `"sleep $(( RANDOM \\% 3600 )); /usr/bin/fusioninventory-agent"`]. + ### Config Specific Variables Some variables used to generate FusionInventery agent.cfg file from Ansible template : diff --git a/defaults/main.yml b/defaults/main.yml index 40174da..92465b3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -59,7 +59,66 @@ fusioninventory__agent_service_name: 'fusioninventory-agent' fusioninventory__agent_service_manage: true # ]]] + +# Cron configuration [[[ +# ----------------------------- +# .. envvar:: fusioninventory__agent_conf_cron [[[ +# +# Instead of running as an agent, run by cron. Can be "absent" or "present" +# +fusioninventory__agent_conf_cron: "absent" # ]]] + +# .. envvar:: fusioninventory__agent_conf_cron_day [[[ +# +# Which days should the agent be ran +# +fusioninventory__agent_conf_cron_day: "*" + # ]]] + +# .. envvar:: fusioninventory__agent_conf_cron_hour [[[ +# +# Which hours should the agent be ran +# +fusioninventory__agent_conf_cron_hour: "23" + # ]]] + +# .. envvar:: fusioninventory__agent_conf_cron_minute [[[ +# +# Which minutes should the agent be ran +# +fusioninventory__agent_conf_cron_minute: "0" + # ]]] + +# .. envvar:: fusioninventory__agent_conf_cron_month [[[ +# +# Which months should the agent be ran +# +fusioninventory__agent_conf_cron_month: "*" + # ]]] + +# .. envvar:: fusioninventory__agent_conf_cron_weekday [[[ +# +# Which weekdays should the agent be ran +# +fusioninventory__agent_conf_cron_weekday: "*" + # ]]] + +# .. envvar:: fusioninventory__agent_conf_cron_user [[[ +# +# Which user should the agent be ran under +# +fusioninventory__agent_conf_cron_user: "root" + # ]]] + +# .. envvar:: fusioninventory__agent_conf_command [[[ +# +# The command should cron run +# +fusioninventory__agent_conf_command: "sleep $(( RANDOM \\% 3600 )); /usr/bin/fusioninventory-agent" + # ]]] + # ]]] + # Configuration [[[ # ----------------------------- diff --git a/tasks/main.yml b/tasks/main.yml index 3ec261e..3644f35 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -56,3 +56,17 @@ mode: '0644' when: fusioninventory__agent_deploy_state == "present" notify: ['restart fusioninventory-agent service'] + + +- name: "Create cron entry when needed" + cron: + name: fusion-inventory-oneshot + cron_file: fusion-inventory-oneshot + day: "{{ fusioninventory__agent_conf_cron_day }}" + hour: "{{ fusioninventory__agent_conf_cron_hour }}" + minute: "{{ fusioninventory__agent_conf_cron_minute }}" + month: "{{ fusioninventory__agent_conf_cron_month }}" + weekday: "{{ fusioninventory__agent_conf_cron_weekday }}" + user: "{{ fusioninventory__agent_conf_cron_user }}" + state: "{{ fusioninventory__agent_conf_cron }}" + job: "{{ fusioninventory__agent_conf_command }}"