From 6c8831c85f44d6161526c73a126e771d8c42f8db Mon Sep 17 00:00:00 2001 From: Debora Benedetto <debora.benedetto@hpe.com> Date: Mon, 25 Jul 2022 15:39:51 +0200 Subject: [PATCH] add monitoring template in ansible --- .../nginx_openstack/terraform/main.tf | 16 ++++----- .../ansible/ubuntu/monitoring/ansible.cfg | 7 ++++ .../monitoring/ansible_requirements.yml | 8 +++++ .../ansible/ubuntu/monitoring/hosts.yaml | 4 +++ .../install_playbook_requirements.sh | 33 +++++++++++++++++++ templates/ansible/ubuntu/monitoring/main.yml | 22 +++++++++++++ .../ansible/ubuntu/monitoring/run-playbook.sh | 33 +++++++++++++++++++ templates/ansible/ubuntu/monitoring/site.yaml | 30 +++++++++++++++++ .../ubuntu/monitoring/site_requirements.yaml | 9 +++++ .../ansible/ubuntu/monitoring/vars/main.yaml | 27 +++++++++++++++ 10 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 templates/ansible/ubuntu/monitoring/ansible.cfg create mode 100644 templates/ansible/ubuntu/monitoring/ansible_requirements.yml create mode 100644 templates/ansible/ubuntu/monitoring/hosts.yaml create mode 100644 templates/ansible/ubuntu/monitoring/install_playbook_requirements.sh create mode 100644 templates/ansible/ubuntu/monitoring/main.yml create mode 100644 templates/ansible/ubuntu/monitoring/run-playbook.sh create mode 100644 templates/ansible/ubuntu/monitoring/site.yaml create mode 100644 templates/ansible/ubuntu/monitoring/site_requirements.yaml create mode 100644 templates/ansible/ubuntu/monitoring/vars/main.yaml diff --git a/output_files_generated/nginx_openstack/terraform/main.tf b/output_files_generated/nginx_openstack/terraform/main.tf index 11c005e..e9ef70a 100644 --- a/output_files_generated/nginx_openstack/terraform/main.tf +++ b/output_files_generated/nginx_openstack/terraform/main.tf @@ -117,14 +117,6 @@ resource "openstack_networking_router_interface_v2" "net1_router_interface" { -# Create ssh keys -resource "openstack_compute_keypair_v2" "ssh_key" { - name = "ubuntu" - # public_key = "ubuntu" -} - - - # CREATING SECURITY_GROUP resource "openstack_compute_secgroup_v2" "icmp" { @@ -172,3 +164,11 @@ resource "openstack_compute_secgroup_v2" "ssh" { } + + +# Create ssh keys +resource "openstack_compute_keypair_v2" "ssh_key" { + name = "ubuntu" + # public_key = "ubuntu" +} + diff --git a/templates/ansible/ubuntu/monitoring/ansible.cfg b/templates/ansible/ubuntu/monitoring/ansible.cfg new file mode 100644 index 0000000..660a5eb --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/ansible.cfg @@ -0,0 +1,7 @@ +# https://docs.ansible.com/ansible/latest/reference_appendices/config.html +[defaults] +host_key_checking = False +inventory = {{CWD}}/hosts.yaml ; This points to the file that lists your hosts +remote_user = esilab +deprecation_warnings=False ; to remove the python version depretation warning +display_skipped_hosts = no \ No newline at end of file diff --git a/templates/ansible/ubuntu/monitoring/ansible_requirements.yml b/templates/ansible/ubuntu/monitoring/ansible_requirements.yml new file mode 100644 index 0000000..58c0cb3 --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/ansible_requirements.yml @@ -0,0 +1,8 @@ +roles: +# - name: dj-wasabi.telegraf +# version: 0.13.2 +# source: https://galaxy.ansible.com + - name: dj-wasabi.telegraf + src: https://github.com/dj-wasabi/ansible-telegraf.git + scm: git + version: 0.13.2 diff --git a/templates/ansible/ubuntu/monitoring/hosts.yaml b/templates/ansible/ubuntu/monitoring/hosts.yaml new file mode 100644 index 0000000..b9cbfc6 --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/hosts.yaml @@ -0,0 +1,4 @@ +all: + hosts: + localhost: + ansible_connection: local diff --git a/templates/ansible/ubuntu/monitoring/install_playbook_requirements.sh b/templates/ansible/ubuntu/monitoring/install_playbook_requirements.sh new file mode 100644 index 0000000..843bf3b --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/install_playbook_requirements.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +SCRIPT_DIR=$(dirname "$0") + +# to avoid the being run in a world writable directory we explicitly assign the ANSIBLE_CONFIG variable +if [[ -f ./ansible.cfg ]] +then + export ANSIBLE_CONFIG=./ansible.cfg +else + if [[ -f $SCRIPT_DIR/ansible.cfg ]] + then + export ANSIBLE_CONFIG=$SCRIPT_DIR/ansible.cfg + fi +fi + +if [[ -z "$ANSIBLE_CONFIG" ]] +then + echo ANSIBLE_CONFIG to assigned using default https://docs.ansible.com/ansible/latest/reference_appendices/config.html +else + echo ANSIBLE_CONFIG=$ANSIBLE_CONFIG +fi + +if [[ -z "$1" ]] +then + # echo without params + echo ansible-playbook $SCRIPT_DIR/site_requirements.yaml + ansible-playbook $SCRIPT_DIR/site_requirements.yaml +else + # echo with params + echo ansible-playbook $SCRIPT_DIR/site_requirements.yaml --extra-vars "$1" + ansible-playbook $SCRIPT_DIR/site_requirements.yaml --extra-vars "$1" +fi diff --git a/templates/ansible/ubuntu/monitoring/main.yml b/templates/ansible/ubuntu/monitoring/main.yml new file mode 100644 index 0000000..657a7ea --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/main.yml @@ -0,0 +1,22 @@ +--- +- hosts: localhost + tasks: + - name: print disclamer + debug: + msg: this can also be done with "ansible-galaxy install -r requirements" + - name: install telegraf from galaxy + community.general.ansible_galaxy_install: + type: role + requirements_file: ansible_requirements.yml + +- hosts: all + pre_tasks: + - name: Ensure gnupg package + package: + name: gnupg + state: present + become: true + vars_files: + - vars/main.yaml + roles: + - dj-wasabi.telegraf \ No newline at end of file diff --git a/templates/ansible/ubuntu/monitoring/run-playbook.sh b/templates/ansible/ubuntu/monitoring/run-playbook.sh new file mode 100644 index 0000000..f2bba22 --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/run-playbook.sh @@ -0,0 +1,33 @@ +#!/bin/bash +set -e + +SCRIPT_DIR=$(dirname "$0") + +# to avoid the being run in a world writable directory we explicitly assign the ANSIBLE_CONFIG variable +if [[ -f ./ansible.cfg ]] +then + export ANSIBLE_CONFIG=./ansible.cfg +else + if [[ -f $SCRIPT_DIR/ansible.cfg ]] + then + export ANSIBLE_CONFIG=$SCRIPT_DIR/ansible.cfg + fi +fi + +if [[ -z "$ANSIBLE_CONFIG" ]] +then + echo ANSIBLE_CONFIG to assigned using default https://docs.ansible.com/ansible/latest/reference_appendices/config.html +else + echo ANSIBLE_CONFIG=$ANSIBLE_CONFIG +fi + +if [[ -z "$1" ]] +then + # echo without params + echo ansible-playbook $SCRIPT_DIR/site.yaml + ansible-playbook $SCRIPT_DIR/site.yaml +else + # echo with params + echo ansible-playbook $SCRIPT_DIR/site.yaml --extra-vars "$1" + ansible-playbook $SCRIPT_DIR/site.yaml --extra-vars "$1" +fi diff --git a/templates/ansible/ubuntu/monitoring/site.yaml b/templates/ansible/ubuntu/monitoring/site.yaml new file mode 100644 index 0000000..531dbf5 --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/site.yaml @@ -0,0 +1,30 @@ +- hosts: all + pre_tasks: + - name: Check parameters + fail: + msg: 'variable {{item}} not defined' + when: item is not defined + with_items: + - pma_deployment_id + - pma_influxdb_bucket + - pma_influxdb_token + - pma_influxdb_org + - pma_influxdb_addr + - name: Print parameters + debug: + msg: + - "pma_deployment_id: {{ pma_deployment_id }}" + - "pma_influxdb_bucket: {{ pma_influxdb_bucket }}" + - "pma_influxdb_token: {{ pma_influxdb_token }}" + - "pma_influxdb_org: {{ pma_influxdb_org }}" + - "pma_influxdb_addr: {{ pma_influxdb_addr }}" + - name: Ensure gnupg package + package: + name: gnupg + state: present + become: true + + vars_files: + - vars/main.yaml + roles: + - dj-wasabi.telegraf diff --git a/templates/ansible/ubuntu/monitoring/site_requirements.yaml b/templates/ansible/ubuntu/monitoring/site_requirements.yaml new file mode 100644 index 0000000..3e7665d --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/site_requirements.yaml @@ -0,0 +1,9 @@ +- hosts: localhost + tasks: + - name: print disclamer + debug: + msg: this can also be done with "ansible-galaxy install -r requirements" + - name: install telegraf from galaxy + community.general.ansible_galaxy_install: + type: role + requirements_file: ansible_requirements.yml diff --git a/templates/ansible/ubuntu/monitoring/vars/main.yaml b/templates/ansible/ubuntu/monitoring/vars/main.yaml new file mode 100644 index 0000000..861faf3 --- /dev/null +++ b/templates/ansible/ubuntu/monitoring/vars/main.yaml @@ -0,0 +1,27 @@ +pma_deployment_id: "123e4567-e89b-12d3-a456-426614174002" +pma_influxdb_bucket: "bucket" +pma_influxdb_token: "piacerePassword" +pma_influxdb_org: "piacere" +pma_influxdb_addr: "https://influxdb.pm.ci.piacere.digital.tecnalia.dev" + +telegraf_agent_package_state: latest + +telegraf_agent_output: + - type: influxdb_v2 + config: + - urls = ["{{ pma_influxdb_addr }}"] + - token = "{{ pma_influxdb_token }}" + - organization = "{{ pma_influxdb_org }}" + - bucket = "{{ pma_influxdb_bucket }}" + - insecure_skip_verify = true + +telegraf_global_tags: + - tag_name: deployment_id + tag_value: "{{ pma_deployment_id }}" + +telegraf_plugins_default: + - plugin: cpu + - plugin: mem + - plugin: processes + - plugin: disk + - plugin: net \ No newline at end of file -- GitLab