106 lines
3.2 KiB
YAML
106 lines
3.2 KiB
YAML
---
|
|
- name: Set up global facts
|
|
gather_facts: true
|
|
hosts: localhost
|
|
become: false
|
|
tasks:
|
|
- ansible.builtin.set_fact:
|
|
vo: d4research
|
|
service: resource_manager
|
|
|
|
|
|
- name: Gracefully stop the running RM container
|
|
hosts: all
|
|
vars:
|
|
vo: "{{ hostvars.localhost.vo }}"
|
|
service: "{{ hostvars.localhost.service }}"
|
|
tasks:
|
|
- ansible.builtin.debug:
|
|
var: groups
|
|
- name: Retrieve Docker container id of the RM
|
|
ansible.builtin.command: "sudo docker service ps --no-trunc --format '{{ '{{' }}json .{{ '}}' }}' -f desired-state=shutdown gcore-{{ vo }}_{{ service | replace('_','-') }}"
|
|
register: service_info
|
|
|
|
- name: Parse results and store
|
|
hosts: localhost
|
|
gather_facts: false
|
|
become: false
|
|
tags: info
|
|
tasks:
|
|
- name: retrieve previous variable
|
|
ansible.builtin.set_fact:
|
|
# var: "hostvars['resource_manager_{{ vo }}']['service_info']"
|
|
service_tasks_str: "{{ hostvars['10.1.40.31']['service_info'].stdout }}"
|
|
- name: create proper json
|
|
ansible.builtin.shell: echo {{ service_tasks_str | quote }} | jq -s
|
|
register: service_tasks_json
|
|
- name: convert to variable
|
|
ansible.builtin.set_fact:
|
|
service_tasks: "{{ service_tasks_json.stdout | from_json }}"
|
|
- name: Print first item
|
|
ansible.builtin.debug:
|
|
var: service_tasks[-1]
|
|
|
|
- name: Resolve Node IP
|
|
hosts: all
|
|
tags: info
|
|
tasks:
|
|
- name: Retrieve hostname
|
|
ansible.builtin.set_fact:
|
|
worker_node: "{{ hostvars['localhost']['service_tasks'][-1]['Node'] }}"
|
|
- name: Retrieve IP
|
|
ansible.builtin.shell: dig +short {{ worker_node }}
|
|
register:
|
|
worker_ip
|
|
- name: Simple A record (IPV4 address) lookup for example.com
|
|
ansible.builtin.debug:
|
|
var: worker_ip.stdout
|
|
|
|
# - name: Stop gCore container on the proper docker container
|
|
# hosts: "{{ worker_ip.stdout }}"
|
|
# tasks:
|
|
# - name: Execute docker to stop the container
|
|
# debug:
|
|
# msg: "sudo docker exec {{ hostvars['localhost']['service_tasks'][-1]['Name'] }}.{{ hostvars['localhost']['service_tasks'][-1]['ID'] }} /home/gcube/gCore/bin/gcore-stop-container"
|
|
|
|
|
|
# - name: create pippo
|
|
# ansible.builtin.set_fact:
|
|
# pippo: ''
|
|
|
|
# - name: Retrieve and convert result to json
|
|
# ansible.builtin.set_fact:
|
|
# container_info: "{{ pippo | from_json }}"
|
|
|
|
# - name: Print results
|
|
# ansible.builtin.debug:
|
|
# msg: "{{ container_info }}[0]"
|
|
|
|
- name: Ripristino Stato Resource Manager
|
|
#hosts: is_registry_devsec:is_registry_devnext
|
|
#hosts: resource_manager_devsec
|
|
gather_facts: false
|
|
hosts: all
|
|
tasks:
|
|
- name: Get info on stack state
|
|
community.docker.docker_stack_info:
|
|
register: result
|
|
- name: Show results
|
|
ansible.builtin.debug:
|
|
var: result.results
|
|
|
|
- name: Shows stack info
|
|
community.docker.docker_stack_task_info:
|
|
name: '{{ resource_manager_docker_stack_name }}'
|
|
register: stack_info
|
|
|
|
- name: Message
|
|
ansible.builtin.debug:
|
|
msg: "Retrieving info about {{ resource_manager_docker_stack_name }}"
|
|
|
|
- name: Show results
|
|
ansible.builtin.debug:
|
|
var: stack_info.results
|
|
|
|
|