From 8c6771bc6c4d46b282256d56751b9a7213bedca8 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Mon, 7 Oct 2024 21:04:19 +0200 Subject: [PATCH] Add top-instances play Signed-off-by: Christian Berendt --- playbooks/generic/ipmi-address.yml | 2 ++ playbooks/generic/top-instances.yml | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 playbooks/generic/top-instances.yml diff --git a/playbooks/generic/ipmi-address.yml b/playbooks/generic/ipmi-address.yml index df6e467..b3748b0 100644 --- a/playbooks/generic/ipmi-address.yml +++ b/playbooks/generic/ipmi-address.yml @@ -22,6 +22,8 @@ ansible.builtin.shell: | set -o pipefail ipmitool lan print | grep "IP Address\s*:" | awk -F: '{ print $2 }' + args: + executable: /bin/bash register: result changed_when: false when: p.stat.exists diff --git a/playbooks/generic/top-instances.yml b/playbooks/generic/top-instances.yml new file mode 100644 index 0000000..9203ed9 --- /dev/null +++ b/playbooks/generic/top-instances.yml @@ -0,0 +1,23 @@ +--- +- name: Get top instances + hosts: "{{ hosts_load_average|default('generic') }}" + serial: "{{ osism_serial['load_average']|default(osism_serial_default)|default(0) }}" + strategy: "{{ osism_strategy|default('linear') }}" + + tasks: + - name: Get top instances + ansible.builtin.shell: | + set -o pipefail + ps -eo pcpu,cmd --sort=-pcpu --no-headers | grep OpenStack | head -n 3 | awk '{ print $0 }' + args: + executable: /bin/bash + register: result + + - name: Print top instances + ansible.builtin.debug: + msg: "{{ item | ansible.builtin.regex_search('([0-9]+\\.[0-9]+).*-uuid ([a-f0-9\\-]{36})', '\\1', '\\2') }}" + loop: "{{ result.stdout_lines }}" + throttle: 1 + loop_control: + index_var: loop_index + label: "{{ loop_index }}"