diff --git a/server/ansible_inventory b/server/ansible_inventory index f822a23..b7da8ca 100644 --- a/server/ansible_inventory +++ b/server/ansible_inventory @@ -1,2 +1,2 @@ -[android-prometheus-exporter-target-server] -139.144.68.186 +[android_prometheus_exporter_target_server] +143.42.59.63 ansible_ssh_private_key_file=../credentials/key \ No newline at end of file diff --git a/server/ansible_playbook.yaml b/server/ansible_playbook.yaml index bd6946e..18fa96c 100644 --- a/server/ansible_playbook.yaml +++ b/server/ansible_playbook.yaml @@ -1,7 +1,7 @@ # run this playbook against new linux server - name: Install example server stack for prometheus-exporter-android - hosts: android-prometheus-exporter-target-server + hosts: android_prometheus_exporter_target_server remote_user: root vars: @@ -46,10 +46,20 @@ state: present update_cache: true + - name: Install or update pip + ansible.builtin.dnf: + name: + - python-pip + - python3-pip + state: present + - name: Install 'docker' package from pip for ansible commands ansible.builtin.pip: - name: docker + name: "{{ item }}" state: present + loop: + - docker + - docker-compose - name: Enable and start docker service ansible.builtin.service: @@ -66,15 +76,20 @@ - name: Reset ssh connection for user group changes to take place ansible.builtin.meta: reset_connection - when: add_docker_group.changed + + - name: Install passlib for new user creation + ansible.builtin.pip: + name: passlib + state: present - name: Create new user ansible.builtin.user: name: "{{ new_user_name }}" shell: /bin/bash + update_password: on_create groups: wheel append: true - password: "{{ new_user_password | password_hash('sha512', general.password_salt) }}" + password: "{{ new_user_password | password_hash('sha512') }}" - name: Execute the following as the new user become: true @@ -82,26 +97,35 @@ tags: configuration block: - name: Copy configuration files - ansible.posix.synchronize: + ansible.builtin.copy: src: ./configuration - dest: "{{ '/home/' + new_user_name + '/configuration' }}" + dest: "{{ '/home/' + new_user_name + '/' }}" owner: "{{ new_user_name }}" group: "{{ new_user_name }}" mode: 0644 force: true register: config_files + - name: Copy docker-compose.yaml + ansible.builtin.copy: + src: ./docker-compose.yaml + dest: "{{ '/home/' + new_user_name + '/docker-compose.yaml' }}" + owner: "{{ new_user_name }}" + group: "{{ new_user_name }}" + mode: 0644 + force: true + register: compose_file + - name: Pull images community.docker.docker_compose: pull: true - recreate: always project_src: "{{ '/home/' + new_user_name }}" - name: Start docker compose community.docker.docker_compose: state: present project_src: "{{ '/home/' + new_user_name }}" - restarted: "{{ config_files.changed | bool }}" + restarted: "{{ (config_files.changed | bool) or (compose_file.changed | bool) }}" - name: Create docker compose systemd service block: diff --git a/server/docker-compose.yaml b/server/docker-compose.yaml index 4813a5b..717a0c5 100644 --- a/server/docker-compose.yaml +++ b/server/docker-compose.yaml @@ -16,13 +16,13 @@ services: networks: - common-network volumes: - - grafana-data:/var/lib/grafana + - grafana-data:/var/lib/grafana #TODO add grafana datasource prometheus by default nginx: container_name: nginx image: nginx:1.23.4 volumes: - - ${PWD}/configuration/nginx.conf:/etc/nginx/nginx.conf + - ./configuration/nginx.conf:/etc/nginx/nginx.conf ports: - 3000:3000 # grafana port - 8080:8080 # pushprox port @@ -44,7 +44,7 @@ services: image: bitnami/prometheus:2.43.0 restart: on-failure volumes: - - ${PWD}/configuration/prometheus.yaml:/etc/prometheus/prometheus.yml + - ./configuration/prometheus.yaml:/etc/prometheus/prometheus.yml networks: - common-network