Add Ansible integration for device management and deployment automation
- Added ansible/ directory with playbooks for: * deploy.yml: Update applications on devices from git * commands.yml: Execute arbitrary commands on devices * system_update.yml: OS updates and health checks * inventory.ini: Device and group configuration * README.md: Comprehensive Ansible guide * requirements.txt: Installation instructions - Added ansible_integration.py: Python module wrapping Ansible operations - Added utils_ansible.py: Updated utilities using Ansible instead of HTTP commands Key benefits: - Idempotent operations with error recovery - Comprehensive logging and backup - Multi-device orchestration - Better reliability and control - Replaces unreliable direct HTTP command execution
This commit is contained in:
51
ansible/commands.yml
Normal file
51
ansible/commands.yml
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
# commands.yml - Execute commands on Prezenta devices
|
||||
# Provides structured command execution with logging and error handling
|
||||
|
||||
- name: Execute Command on Prezenta Devices
|
||||
hosts: "{{ target_devices | default('prezenta_devices') }}"
|
||||
gather_facts: no
|
||||
|
||||
vars:
|
||||
command_to_run: "{{ command | default('pwd') }}"
|
||||
command_user: pi
|
||||
log_commands: true
|
||||
|
||||
tasks:
|
||||
- name: Display command execution info
|
||||
debug:
|
||||
msg: |
|
||||
Executing on: {{ inventory_hostname }} ({{ ansible_host }})
|
||||
Command: {{ command_to_run }}
|
||||
User: {{ command_user }}
|
||||
|
||||
- name: Execute command
|
||||
shell: "{{ command_to_run }}"
|
||||
register: command_result
|
||||
become: yes
|
||||
become_user: "{{ command_user }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Display command output
|
||||
debug:
|
||||
msg: |
|
||||
Return Code: {{ command_result.rc }}
|
||||
STDOUT:
|
||||
{{ command_result.stdout }}
|
||||
STDERR:
|
||||
{{ command_result.stderr | default('None') }}
|
||||
|
||||
- name: Log command execution
|
||||
lineinfile:
|
||||
path: "{{ app_directory }}/data/command_history.log"
|
||||
line: "[{{ ansible_date_time.iso8601 }}] [{{ inventory_hostname }}] Command: {{ command_to_run }} | RC: {{ command_result.rc }}"
|
||||
create: yes
|
||||
state: present
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
become: yes
|
||||
when: log_commands
|
||||
|
||||
- name: Fail if command failed
|
||||
fail:
|
||||
msg: "Command failed on {{ inventory_hostname }} with return code {{ command_result.rc }}"
|
||||
when: command_result.rc != 0 and fail_on_error | default(false)
|
||||
Reference in New Issue
Block a user