This commit is contained in:
2024-06-14 08:40:04 +02:00
parent 1ec41c82d9
commit baa8139899
33 changed files with 823 additions and 68 deletions

12
ansible.cfg Normal file
View File

@@ -0,0 +1,12 @@
[defaults]
inventory = inventory/inventory.yml
host_key_checking = False
retry_files_enabled = False
[httpapi]
# This section is used to configure the httpapi connection plugin
connections = community.zabbix.zabbix
[connection]
socket_path = /var/run/ansible/socket # Ensure this is set correctly

47
apt_update_upgrade.yml Normal file
View File

@@ -0,0 +1,47 @@
---
- name: Update and upgrade all packages
hosts: all
become: true
tasks:
- name: Gather facts
ansible.builtin.setup:
- name: Update the apt package index
ansible.builtin.apt:
update_cache: true
- name: Upgrade all packages to the latest version
ansible.builtin.apt:
upgrade: dist
- name: Autoremove unnecessary packages
ansible.builtin.apt:
autoremove: true
- name: Clean up the apt cache
ansible.builtin.apt:
autoclean: true
- name: Check if a reboot is required
ansible.builtin.stat:
path: /var/run/reboot-required
register: reboot_required_stat
- name: Reboot the system if a reboot is required
ansible.builtin.reboot:
msg: "Reboot initiated by Ansible because updates require a restart"
connect_timeout: 5
reboot_timeout: 600
pre_reboot_delay: 0
post_reboot_delay: 30
when: reboot_required_stat.stat.exists == true
- name: Wait for the system to come back online
ansible.builtin.wait_for_connection:
timeout: 300
when: reboot_required_stat.stat.exists == true
- name: Display reboot result
ansible.builtin.debug:
var: reboot_required_stat
when: reboot_required_stat.stat.exists == true

68
clone_ubu1.yml Normal file
View File

@@ -0,0 +1,68 @@
---
- name: List VMs, Templates, and Clone Ubuntu server on Proxmox
hosts: proxmox.localdomain
gather_facts: no
vars:
api_host: "192.168.1.162"
api_user: "root@pam"
api_token_id: "mytoki"
api_token_secret: "ea5114f5-ed39-4277-ac09-a32984be5bc9"
proxmox_node: "pve" # Add your Proxmox node name here
vars_prompt:
- name: new_vm_name
prompt: "Enter the name for the new VM"
private: no
tasks:
- name: List all VMs and templates
community.general.proxmox_vm_info:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
validate_certs: no
register: vms_info
- name: Print VM and template names and states
debug:
msg: "{{ item.name }} - {{ item.status }}"
loop: "{{ vms_info.proxmox_vms }}"
- name: Find VMID based on VM name
set_fact:
source_vmid: "{{ item.vmid }}"
loop: "{{ vms_info.proxmox_vms }}"
when: item.name == "ubu-srv01"
- name: Debug source VMID
debug:
msg: "Source VMID: {{ source_vmid }}"
- name: Clone VM to create new Ubuntu server
community.general.proxmox_kvm:
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
api_host: "{{ api_host }}"
clone: "ubu-srv01"
name: "{{ new_vm_name }}"
node: "{{ proxmox_node }}"
storage: "local"
format: "qcow2"
full: true
timeout: 240
validate_certs: no
- name: List all VMs and templates after cloning
community.general.proxmox_vm_info:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
validate_certs: no
register: vms_info_after_clone
- name: Print VM and template names and states after cloning
debug:
msg: "{{ item.name }} - {{ item.status }}"
loop: "{{ vms_info_after_clone.proxmox_vms }}"

22
create_vm.yml Normal file
View File

@@ -0,0 +1,22 @@
---
- name: Create a new VM with minimal options
hosts: proxmox.localdomain
gather_facts: false
vars:
proxmox_host: 192.168.1.162
proxmox_user: root
proxmox_token_id: mytoken1
proxmox_token_secret: 313c6ffd-6753-4fc4-a433-bc1f00840d36
vm_name: spynal
node_name: pve
tasks:
- name: Create new VM with minimal options
community.general.proxmox_kvm:
api_user: "{{ proxmox_user }}"
api_token_id: "{{ proxmox_user }}!{{ proxmox_token_id }}"
api_token_secret: "{{ proxmox_token_secret }}"
api_host: "{{ proxmox_host }}"
name: "{{ vm_name }}"
node: "{{ node_name }}"
state: present

View File

@@ -1,18 +1,18 @@
$ANSIBLE_VAULT;1.1;AES256
62346336663164653438616234363436306566383937343434366163363663343836343861643466
6562343430616231646137646533663139666535656636390a393434333766326335653338313161
62373031396564366438343939386364353030343365393332376338663634336565316633363739
6665313231666262620a643662353766383761616662363637666539313362306236613162306163
34366635366664623831393534346366653838646236613136393233393533376230333231373730
35306566643366363163306438373538656332356666386238363833356334363262663637653532
30643330373864623437363066623839313235656636613638666661633361313566653432373663
62366437373931396663336263343939373235636661373032376265383263376338316530303839
62323262356234323737303935353165633635366430363734376166626466633237643231313966
66626162323962653238393036626537666233663335616466633965663934316239636663636430
33323965656464643239323333306231353335323665626332356131353430333038396339373363
36613566623337363538353438623237366134346661386464323532653737306537393435623934
61313238333038363931613938626464653435396437336365396161663931303732313133613965
37316132643162666631653264613132623933326661353266613863356165653832303565393832
63373365333939353435323261613938353133306166393536613332613634346533313835656534
36303462363666653736383262306664373433326635313939633238333864353463353936396430
6430
36623839393830613036376232373165313130666538666663626434396433373965666537396233
3530646333363064663634626562623866626231646631620a353961623135306537666435323066
66313535663636333336333162366435323132653361333434653437623932316438313837303962
6364333732303239350a633137306465363639633262326363316637633539643730333730636635
30326334346437393062306663353831653763653461396664393830316462313534376238646437
35636435353635633734303032366366633134373539333137613534633263613665363765393933
33356332613466393430663735376135333266343961326431666233616531373130343133373766
38303332316539656266303061376266393161393838373739663931323864346165653030343162
35386665303865313533363130643230623634643630656637336632633961656139336536303634
63346433636232653862353937666433633730343831336133666331646634356265646235363739
63646231623765623135366162376134613439633737353062653235386636303536366362393565
36366436333639383963343563393163366233656630643933316637346231356166386238346435
30373837636139313862333165353437316439633830383064396532383563363466636166376135
63633035323336343161396437303731333263616136346661393264643030336433343739653964
33363933353736313539623631323662303438663462393634363563363662306437636430636538
65373433393663303430643464623638646432643131393032633563343339343730383033646265
3439

10
dyn_inv.yml Normal file
View File

@@ -0,0 +1,10 @@
---
- name: Gather facts from discovered hosts
hosts: all
tasks:
- name: Collect facts
ansible.builtin.setup:
- name: Display gathered facts
ansible.builtin.debug:
var: ansible_facts

32
dynamic_inventory.py Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env python3
import json
import subprocess
def get_hosts():
# Use nmap to discover hosts
result = subprocess.run(['nmap', '-sn', '192.168.1.0/24'], stdout=subprocess.PIPE)
output = result.stdout.decode()
hosts = []
for line in output.split('\n'):
if 'Nmap scan report for' in line:
hosts.append(line.split(' ')[-1])
return hosts
def main():
hosts = get_hosts()
inventory = {
'all': {
'hosts': hosts,
'vars': {
'ansible_connection': 'ssh',
'ansible_user': 'alex',
'ansible_ssh_private_key_file': '~/.ssh/id_ed25519'
}
}
}
print(json.dumps(inventory))
if __name__ == '__main__':
main()

3
group_vars/all.yml Normal file
View File

@@ -0,0 +1,3 @@
---
ansible_user: alex
ansible_ssh_private_key_file: ~/.ssh/id_ed25519

101
install_zabbix_agent.yml Normal file
View File

@@ -0,0 +1,101 @@
---
# tasks file for zabbix-agent
# Uninstall Zabbix agent
- name: Uninstall Zabbix agent
yum:
name: zabbix-agent
state: absent
# Install Zabbix agent
- name: Install Zabbix agent
yum:
name: zabbix-agent
state: installed
# Delete Zabbix PSK if zabbix_overwrite_psk is true
- name: Delete Zabbix psk
file:
path: /etc/zabbix/zabbix_agentd.psk
state: absent
when: zabbix_overwrite_psk|bool
# Generate Zabbix PSK
- name: Generate Zabbix psk
command: openssl rand -hex -out /etc/zabbix/zabbix_agentd.psk 32
creates: /etc/zabbix/zabbix_agentd.psk
# Change the owner of zabbix_agentd.psk to zabbix
- name: Change the owner of zabbix_agentd.psk to zabbix
file:
path: /etc/zabbix/zabbix_agentd.psk
owner: zabbix
# Register Zabbix agent PSK
- name: Register Zabbix agent psk
command: cat /etc/zabbix/zabbix_agentd.psk
register: zabbix_psk
# Configure Zabbix agent
- name: Configure Zabbix agent
template:
src: zabbix-agent.conf
dest: /etc/zabbix/zabbix_agentd.d/agent.conf
# Ensure that /etc/zabbix/zabbix_agentd.d is included in conf
- name: Ensure that /etc/zabbix/zabbix_agentd.d is included in conf
ini_file:
path: /etc/zabbix_agentd.conf
option: Include
value: /etc/zabbix/zabbix_agentd.d/*.conf
backup: true
# Create a new host or update an existing host's info
- name: Create a new host or update an existing host's info
vars:
ansible_network_os: community.zabbix.zabbix
ansible_connection: httpapi
ansible_httpapi_port: 443
ansible_httpapi_use_ssl: true
ansible_httpapi_validate_certs: false
ansible_zabbix_url_path: /
ansible_zabbix_auth_key: ad7d2b1e80fa86567d08ac18f4737aabbfd3ab7e91faf205f39a8e7b55b8d7a8
ansible_host: 192.168.1.24
ignore_errors: true
delegate_to: 192.168.1.24
connection: local
zabbix_host:
host_name: "{{ inventory_hostname }}"
visible_name: "{{ inventory_hostname }}"
host_groups:
- "{{ zabbix_host_groups }}"
link_templates:
- "{{ zabbix_link_template }}"
status: enabled
state: present
inventory_mode: automatic
interfaces:
- type: 1
main: 1
useip: 1
ip: "{{ ansible_default_ipv4.address }}"
dns: "{{ inventory_hostname }}"
port: "{{ zabbix_port | default(10050) }}"
tls_connect: 2
tls_accept: 2
tls_psk_identity: "PSK-{{ inventory_hostname }}"
tls_psk: "{{ zabbix_psk.stdout }}"
proxy: "{{ zabbix_proxy | default(omit) }}"
become: false
# Enable Zabbix on Reboot
- name: Enable Zabbix on Reboot
service:
name: zabbix-agent
enabled: true
# Restart Zabbix
- name: Restart Zabbix
service:
name: zabbix-agent
state: restarted

2
inventory.cfg Normal file
View File

@@ -0,0 +1,2 @@
[defaults]
inventory = inventory/inventory.yml

View File

@@ -1,34 +0,0 @@
all:
hosts:
ubnt:
ansible_host: 192.168.1.1
localhost-live.localdomain:
ansible_host: 192.168.1.10
SonosZP.localdomain:
ansible_host: 192.168.1.16
alw.dk.localdomain:
ansible_host: 192.168.1.18
Chromecast.localdomain:
ansible_host: 192.168.1.25
office.localdomain:
ansible_host: 192.168.1.112
00178862792d.localdomain:
ansible_host: 192.168.1.117
Google-Nest-Mini:
ansible_host: 192.168.1.171
OnePlus-8-Pro.localdomain:
ansible_host: 192.168.1.185
wlan0.localdomain:
ansible_host: 192.168.1.187
Galaxy-A33-5G.localdomain:
ansible_host: 192.168.1.201
raspii.localdomain:
ansible_host: 192.168.1.202
unifi:
ansible_host: 192.168.1.237
livingroom.localdomain:
ansible_host: 192.168.1.238
Bedroom.localdomain:
ansible_host: 192.168.1.240
roborock-vacuum-a15.localdomain:
ansible_host: 192.168.1.247

View File

@@ -1,20 +1,27 @@
192.168.1.1
192.168.1.10
192.168.1.15
192.168.1.16
192.168.1.18
192.168.1.22
192.168.1.23
192.168.1.24
192.168.1.25
192.168.1.112
192.168.1.113
192.168.1.117
192.168.1.132
192.168.1.144
192.168.1.153
192.168.1.163
192.168.1.171
192.168.1.185
192.168.1.182
192.168.1.187
192.168.1.194
192.168.1.195
192.168.1.201
192.168.1.202
192.168.1.228
192.168.1.232
192.168.1.237
192.168.1.238
192.168.1.239
192.168.1.240
192.168.1.247
192.168.1.248

48
inventory/inventory.yml Normal file
View File

@@ -0,0 +1,48 @@
---
all:
children:
servers:
hosts:
ubu.localdomain:
ansible_host: 192.168.1.23
ansible_user: alex
raspii.localdomain:
ansible_host: 192.168.1.24
ansible_user: alex
ansible_python_interpreter: /usr/bin/python3
proxmox.localdomain:
ansible_host: 192.168.1.162
ansible_user: root
ansible_password: Aase#1234!
ansible_python_interpreter: /root/proxmoxer_env/bin/python
vars:
proxmox_host: 192.168.1.162
proxmox_user: root@pam
proxmox_token_id: root@pam!mytoken1
proxmox_token_secret: 313c6ffd-6753-4fc4-a433-bc1f00840d36
alex-ds215.localdomain:
ansible_host: 192.168.1.133
ansible_user: alex
ansible_password: o2UK70Evg&^LReS@
ansible_python_interpreter: /usr/bin/python2
ubugpu.localdomain:
ansible_host: 192.168.1.144
ansible_user: alex
ansible_python_interpreter: /usr/bin/python3
alex-ds414.localdomain:
ansible_host: 192.168.1.113
ansible_user: alexadmin
ansible_python_interpreter: /usr/bin/python3
ansible_password: $ZD7P=.X2@e,Ju;
# network_devices:
# hosts:
# USG-PRO-4:
# ansible_host: 192.168.1.1
# ansible_user: alexpolo
# ansible_password: o3vTbA3WBlmghEOg
# ansible_network_os: vyos.vyos
other_devices:
hosts:
localhost-live.localdomain:
ansible_host: 192.168.1.10

22
list-hyperv-vms.yml Normal file
View File

@@ -0,0 +1,22 @@
---
- name: List all Hyper-V Virtual Machines
hosts: homeserver.localdomain
gather_facts: false
vars:
winrmadmin_username: "ansible_user"
winrmadmin_password: "YourStrongPasswordHere"
tasks:
- name: Get WinRM credentials from Ansible Vault
ansible.builtin.include_vars:
file: /home/alex/git/ansible/credentials.yml
name: vault_vars
- name: List Hyper-V virtual machines
ansible.windows.win_shell: |
Get-VM | Select-Object Name, State, MemoryAssigned, ProcessorCount, Uptime
register: vm_info
- name: Debug virtual machine information
ansible.builtin.debug:
var: vm_info.stdout_lines

52
list_proxmox.yml Normal file
View File

@@ -0,0 +1,52 @@
---
- name: List VMs, Templates, and ISOs on Proxmox
hosts: proxmox.localdomain
gather_facts: no
vars:
api_host: "192.168.1.162"
api_user: "root@pam"
api_token_id: "mytoki"
api_token_secret: "ea5114f5-ed39-4277-ac09-a32984be5bc9"
proxmox_node: "pve" # Add your Proxmox node name here
tasks:
- name: List all VMs
community.general.proxmox_vm_info:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
validate_certs: no
register: vms_info
- name: Print VM info
debug:
var: vms_info
- name: List all nodes
community.general.proxmox_node_info:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
validate_certs: no
register: nodes_info
- name: Print node info
debug:
var: nodes_info
- name: List all ISOs
community.general.proxmox_storage_contents_info:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
validate_certs: no
storage: local
node: "{{ proxmox_node }}"
register: isos_info
- name: Print ISO info
debug:
var: isos_info

11
nmap.yml Normal file
View File

@@ -0,0 +1,11 @@
---
plugin: ansible.builtin.nmap
strict: false
address: 192.168.1.0/24
exclude: 192.168.1.1
command: '-sn'
keyed_groups:
- prefix: 'os_'
key: 'os'
compose:
ansible_host: ip

51
remove_vm.yml Normal file
View File

@@ -0,0 +1,51 @@
---
- name: Remove VM on Proxmox
hosts: proxmox.localdomain
gather_facts: no
vars:
api_host: "192.168.1.162"
api_user: "root@pam"
api_token_id: "mytoki"
api_token_secret: "ea5114f5-ed39-4277-ac09-a32984be5bc9"
proxmox_node: "pve"
vars_prompt:
- name: vm_name_to_remove
prompt: "Enter the name of the VM to remove"
private: no
tasks:
- name: List all VMs and templates
community.general.proxmox_vm_info:
api_host: "{{ api_host }}"
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
validate_certs: no
register: vms_info
- name: Find VMID based on VM name
set_fact:
vmid_to_remove: "{{ item.vmid }}"
loop: "{{ vms_info.proxmox_vms }}"
when: item.name == vm_name_to_remove
- name: Debug VMID to remove
debug:
msg: "VMID to remove: {{ vmid_to_remove }}"
when: vmid_to_remove is defined
- name: Remove the VM
community.general.proxmox_kvm:
api_user: "{{ api_user }}"
api_token_id: "{{ api_token_id }}"
api_token_secret: "{{ api_token_secret }}"
api_host: "{{ api_host }}"
vmid: "{{ vmid_to_remove }}"
node: "{{ proxmox_node }}"
state: absent
when: vmid_to_remove is defined
- name: Print message if VM was not found
debug:
msg: "VM {{ vm_name_to_remove }} not found."
when: vmid_to_remove is not defined

View File

@@ -4,8 +4,8 @@
- name: Login to UniFi controller
community.unifi.unifi_controller:
baseurl: "{{ unifi_baseurl }}"
username: "{{ unifi_username }}"
password: "{{ unifi_password }}"
username: "{{ unifiusername }}"
password: "{{ unifipassword }}"
site_id: "{{ unifi_site_id | default('default') }}"
validate_certs: "{{ unifi_validate_certs | default('no') }}"
delegate_to: localhost

View File

@@ -0,0 +1,38 @@
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).

View File

@@ -0,0 +1,12 @@
---
# defaults file for zabbix_agent
zabbix_server_ip: "192.168.1.24"
zabbix_psk_file: "/etc/zabbix/zabbix_agentd.psk"
zabbix_agent_conf: "/etc/zabbix/zabbix_agentd.conf"
zabbix_log_file: "/var/log/zabbix/zabbix_agentd.log"
zabbix_pid_file: "/var/run/zabbix/zabbix_agentd.pid"
zabbix_include_dir: "/etc/zabbix/zabbix_agentd.d"
zabbix_host_groups: []
zabbix_link_template: []
zabbix_port: 10050
zabbix_proxy: null

View File

@@ -0,0 +1,7 @@
---
# handlers file for zabbix-agent
- name: restart zabbix-agent
service:
name: zabbix-agent
state: restarted

View File

@@ -0,0 +1,34 @@
galaxy_info:
author: your name
description: your role description
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.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
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.

View File

@@ -0,0 +1,92 @@
---
# tasks file for zabbix-agent
# Update apt cache
- name: Update apt cache
apt:
update_cache: yes
# Uninstall Zabbix agent (apt version)
- name: Uninstall Zabbix agent
apt:
name: zabbix-agent
state: absent
ignore_errors: true
# Install Zabbix agent (apt version)
- name: Install Zabbix agent
apt:
name: zabbix-agent
state: present
# Generate Zabbix PSK
- name: Generate Zabbix psk
command: openssl rand -hex 32
register: generated_psk
# Write the PSK to a file
- name: Create Zabbix PSK file
copy:
content: "{{ generated_psk.stdout }}"
dest: "{{ zabbix_psk_file }}"
owner: zabbix
mode: '0600'
# Register Zabbix agent PSK
- name: Register Zabbix agent PSK
set_fact:
zabbix_psk: "{{ generated_psk.stdout }}"
# Ensure the zabbix-agent configuration is correct
- name: Configure Zabbix agent
template:
src: zabbix-agent.conf.j2
dest: "{{ zabbix_agent_conf }}"
owner: zabbix
mode: '0644'
notify:
- restart zabbix-agent
# Ensure that include directory is configured
- name: Ensure that /etc/zabbix/zabbix_agentd.d is included in conf
ini_file:
path: "{{ zabbix_agent_conf }}"
section: ""
option: Include
value: "{{ zabbix_include_dir }}/*.conf"
backup: true
notify:
- restart zabbix-agent
# Create a new host or update an existing host's info
- name: Create a new host or update an existing host's info
community.zabbix.zabbix_host:
server_url: "https://{{ zabbix_server_ip }}"
login_user: "Admin" # Change as per your Zabbix server configuration
login_password: "zabbix" # Change as per your Zabbix server configuration
host_name: "{{ inventory_hostname }}"
visible_name: "{{ inventory_hostname }}"
groups:
- "{{ zabbix_host_groups }}"
templates:
- "{{ zabbix_link_template }}"
status: 0
interfaces:
- type: 1
main: 1
useip: 1
ip: "{{ ansible_default_ipv4.address }}"
dns: "{{ inventory_hostname }}"
port: "{{ zabbix_port | default(10050) }}"
tls_connect: 2
tls_accept: 2
tls_psk_identity: "PSK-{{ inventory_hostname }}"
tls_psk: "{{ zabbix_psk }}"
state: present
become: false
# Enable Zabbix on Reboot
- name: Enable Zabbix on Reboot
service:
name: zabbix-agent
enabled: yes

View File

@@ -0,0 +1,10 @@
Server={{ zabbix_server_ip }}
TLSConnect=psk
TLSAccept=psk
TLSPSKIdentity=PSK-{{ inventory_hostname }}
TLSPSKFile={{ zabbix_psk_file }}
# Additional configuration options
LogFile={{ zabbix_log_file }}
PidFile={{ zabbix_pid_file }}
Include={{ zabbix_include_dir }}/*.conf

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- zabbix_agent

View File

@@ -0,0 +1,2 @@
---
# vars file for zabbix_agent

View File

@@ -0,0 +1,23 @@
---
- name: Test Zabbix API connection
hosts: localhost
gather_facts: no
tasks:
- name: Set API token
ansible.builtin.set_fact:
ansible_zabbix_auth_key: "6965e0d3bf4416a15ce750e7dba47933d3dfc988d99d866291b0f2d55845bb05"
- name: Configure HTTPAPI connection
ansible.builtin.set_fact:
ansible_httpapi_use_ssl: false
ansible_httpapi_validate_certs: false
- name: Test Zabbix API connection
community.zabbix.zabbix_api_info:
http_login_user: "Admin"
http_login_password: "zabbix"
register: result
- name: Debug Zabbix API version
debug:
var: result

16
testplaybook.yml Normal file
View File

@@ -0,0 +1,16 @@
---
- name: Test Playbook
hosts: all
pre_tasks:
- name: Include vault variables
ansible.builtin.include_vars:
file: vault.yml
no_log: true
tasks:
- name: Ping all hosts
ansible.builtin.ping:
- name: Gather facts
ansible.builtin.setup:
when: "'ansible_host' in hostvars[inventory_hostname]"

View File

@@ -0,0 +1,17 @@
---
# File: unifi-dhcp-clients-list.yml
- name: Fetch and List DHCP Clients from UniFi Controller
hosts: localhost
gather_facts: no
vars_files:
- credentials.yml
vars:
unifi_baseurl: "https://your-unifi-controller:8443"
unifi_site_id: "default"
unifi_validate_certs: no
roles:
- unifi_dhcp_clients_list

View File

@@ -1,11 +1,27 @@
$ANSIBLE_VAULT;1.1;AES256
38623566643332353464323834656539393636616165353862343864646431626563646539633331
3530303830613564366233373838643565353939333936660a316131366534353537366537626133
39663465366230373930306562613337336530303766313465376466396638383165373234376130
3533306137666663350a356434393530646561366534636438373531663032363061393830646631
36313734383537636532633830663766643034313634353833363865356564366363623038653362
34393163316335323633333636623262306165333237343137343238353538353433653765323133
66323336366363633936306438353237303739323166643465643935356462393463383938333238
63626334333839663130383762653861363534666337326538663934653633623031626335393136
38653636333636303938373230626466633638616165303163666630323034343537383661333934
3466666137383432323961633964353665656534636231333162
33386562613236623035653666303166393132653532653937653930383937303438646633376230
6535666430376161373438356436323265336366663363610a636365623636343932666661373430
65333131343533646338396530303165333063663536313639373537333766323062326631653265
6261663032323130350a636531663565336139663936663266313737613539613438656363623061
31663465316233353764373561323132636663313036396133366164613765626536363863316333
62343834383164316666303937343035363630353737363237333739663563366235336330633261
66396563616639626665333332363634633438613231613663353339373336626265646665366536
33366532353733633562323237646166303831323763653465326636636461616237306230303634
65363266373266303166333238633532336234343039656164636639343064346330633438613639
33663733316134396266306132303665373461316539326465633265366637356233316531616639
64613536343266336436613662623531663665333561623135626338656435653739303564613537
35316636343466383534313165396630323363373466633334333337353762306535303332376337
31306665313736396330663737383836643331336539373134363430663362643332363261373733
36326163336631303430313739656332633065346463393639656134633861393336393263623631
63633230626331626461386131336237353963323735366233623833313236616466353665643539
30306337303236323664646135303663343538623462623637366635373335373363303638326237
31326134623233323565306230356634313565333263363230333538646139643231633761633136
38376164363933373461333237633631646666343539363963383030343434323965336232356263
31303231626666333833356634313433343332643063303731316362366361393132656437346534
33613637376630616664373939343831363231613939303064383733663335666135643735383864
34336439613237343031393862373166313833376366376464636237376333653838396331356531
61353963656466626135323666306430383531313439376265626132656565366639313237633338
62353165623833393631646530346266376432313935393863356435633861653038303363323537
38343231353062643866336265646431353262633834323366353764373439666134656338626266
61343364313737386666643565393237303464306436353566393535623835653961376536386638
6235343135306666393230653431303661376663663030356563

21
verify_ssh.yml Normal file
View File

@@ -0,0 +1,21 @@
---
- name: Verify SSH Connectivity
hosts: all
tasks:
- name: Gather facts for network devices
when: ansible_network_os is defined
ansible.netcommon.cli_command:
command: show version
register: result
- name: Print version for network devices
when: ansible_network_os is defined
debug:
msg: "{{ result.stdout }}"
- name: Gather facts for regular servers
when: ansible_network_os is not defined
ansible.builtin.setup:
- name: Ping all hosts
ansible.builtin.ping:

6
zabbix-agent.yml Normal file
View File

@@ -0,0 +1,6 @@
---
- name: Configure Zabbix Agent
hosts: all
become: true
roles:
- zabbix_agent