From d75f4ffb3fb1cd5e25c919c61e45c958f72c91ef Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Jan 2024 17:19:38 +0100 Subject: [PATCH] zabbix ajout auto --- roles/zabbix-cli/defaults/main.yml | 3 ++- roles/zabbix-cli/tasks/main.yml | 9 +++++++-- roles/zabbix-cli/templates/hostcreate.sh.j2 | 1 + 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 roles/zabbix-cli/templates/hostcreate.sh.j2 diff --git a/roles/zabbix-cli/defaults/main.yml b/roles/zabbix-cli/defaults/main.yml index 33b0a33..8e5d00a 100644 --- a/roles/zabbix-cli/defaults/main.yml +++ b/roles/zabbix-cli/defaults/main.yml @@ -1,2 +1,3 @@ SERVER: "127.0.0.1" -SERVERACTIVE: "172.16.0.8" +SERVERACTIVE: "192.168.99.8" +TOKENAPI: "f72473b7e5402a5247773e456f3709dcdd5e41792360108fc3451bbfeed8eafe" diff --git a/roles/zabbix-cli/tasks/main.yml b/roles/zabbix-cli/tasks/main.yml index 30bc0c4..5b6491e 100644 --- a/roles/zabbix-cli/tasks/main.yml +++ b/roles/zabbix-cli/tasks/main.yml @@ -28,6 +28,11 @@ state: restarted enabled: yes - #- name: remonter les machines - #command: curl -X POST -H "Content-Type: application/json" -d '{ "jsonrpc":"2.0","method":"host.create","params": {"host": "s-itil","groups": [{"groupid": "6"}],"templates": [{"templateid": "10343"}],"inventory_mode": 0,"inventory": {"type": 0}},"auth": "a44e2a4977d61a869437739cb6086ae42f4b9937fbb96aed24bbad028469a1cf","id": 1}' http://192.168.99.8/zabbix/api_jsonrpc.php + - name: mise ne place script hostcreate + template: + src: hostcreate.sh.j2 + dest: /tmp/hostcreate.sh + + - name: lancement script hostcreate + command: bash /tmp/hostcreate.sh diff --git a/roles/zabbix-cli/templates/hostcreate.sh.j2 b/roles/zabbix-cli/templates/hostcreate.sh.j2 new file mode 100644 index 0000000..49b075b --- /dev/null +++ b/roles/zabbix-cli/templates/hostcreate.sh.j2 @@ -0,0 +1 @@ +curl -X POST -H "Content-Type: application/json" -d '{ "jsonrpc":"2.0","method":"host.create","params": {"host": "{{ ansible_hostname }}","groups": [{"groupid": "6"}],"templates": [{"templateid": "10343"}],"inventory_mode": 0,"inventory": {"type": 0}},"auth": "{{ TOKENAPI }}","id": 1}' http://{{ SERVERACTIVE }}/zabbix/api_jsonrpc.php