Sanjay Chari cd9c30c1a1 Fix in sqlalchemy collectd plugin
While evaluating the conditional statement
(when: (('Controller' in group_names) and ('plugin=collectd' not in item.stdout) and sqlalchemy_collectd_plugin)),
if sqlalchemy_collectd_plugin is set to false, the register db_connections does not store any output as the
step (Get mysql string) is skipped. This causes the error (dict object has no attribute stdout).
This patch fixes the issue by placing the condition check ('plugin=collectd' not in item.stdout) at the end of
the when statement, and due to lazy evaluation of conditional statements in Ansible, the condition check is skipped
if sqlalchemy_collectd_plugin is set to false.

Change-Id: I20302e43318c969fb15acd8e78d30cc7c5c208af
2021-12-09 11:04:54 +05:30

222 lines
7.8 KiB
YAML

---
- name: Fetch log file paths
include_vars:
file: "vars/{{ rhosp_major }}.yml"
- name: (Undercloud) Get ctlplane ip address
shell: ip r | egrep 'br-ctlplane\s*proto kernel' | awk '{print $NF}'
register: undercloud_ctlplane_ip_address
when: "'Undercloud' in group_names"
- name: Configure mysql for collectd.conf
block:
- name: (Controller) Get mysql root password
command: hiera -c /etc/puppet/hiera.yaml mysql::server::root_password
become: true
register: mysql_root_password
when: "'Controller' in group_names"
- name: (Undercloud) Get mysql root password
shell: |
grep undercloud_mysql_root_password: undercloud-passwords.conf | sed 's/undercloud_mysql_root_password: //g'
register: undercloud_mysql_password
when: "'Undercloud' in group_names"
- name: Configure rabbitmq monitoring
block:
- name: (Undercloud) Get Rabbitmq username
command: hiera -c /etc/puppet/hiera.yaml rabbitmq::default_user
become: true
register: undercloud_rabbitmq_username
when: "('Undercloud' in group_names and rabbitmq_undercloud_collectd_plugin)"
- name: (Undercloud) Get Rabbitmq password
shell: |
grep undercloud_rabbit_password /home/stack/undercloud-passwords.conf | sed 's/undercloud_rabbit_password: //g'
register: undercloud_rabbitmq_password
when: "('Undercloud' in group_names and rabbitmq_undercloud_collectd_plugin)"
- name: (Controller) Get Rabbitmq username
command: hiera -c /etc/puppet/hiera.yaml rabbitmq::default_user
register: controller0_rabbitmq_username
become: true
when: "'Controller' in group_names and rabbitmq_controller_collectd_plugin and inventory_hostname == groups['Controller'][0]"
- name: (Controller) Get Rabbitmq password
command: hiera -c /etc/puppet/hiera.yaml rabbitmq::default_pass
register: controller0_rabbitmq_password
become: true
when: "'Controller' in group_names and rabbitmq_controller_collectd_plugin and inventory_hostname == groups['Controller'][0]"
- name: Check if Container Files Directory exists
stat:
path: "{{ ansible_user_dir }}/browbeat/browbeat-containers/collectd-openstack"
register: directory_exists
- name: Clone browbeat if it doesn't exists on host
git:
repo: https://github.com/openstack/browbeat.git
dest: "{{ ansible_user_dir }}/browbeat"
version: master
when: not (directory_exists.stat.isdir is defined and directory_exists.stat.isdir)
- name: Get mysql string
shell: "crudini --get {{item.value.path}} database connection"
become: true
register: db_connections
with_dict: "{{mysql_svcs}}"
when: ('Controller' in group_names and sqlalchemy_collectd_plugin)
ignore_errors: true
- name: Append to mysql string
ini_file:
backup: true
dest: "{{ item.item.value.path }}"
section: database
option: connection
value: "{{ item.stdout }}&plugin=collectd&collectd_program_name={{ item.item.key }}"
when: (('Controller' in group_names) and sqlalchemy_collectd_plugin and ('plugin=collectd' not in item.stdout))
with_items: "{{ db_connections.results }}"
become: true
- name: restart containers
shell: podman restart {{ item }}
become: true
with_items:
- cinder_api
- cinder_api_cron
- cinder_scheduler
- nova_conductor
- nova_api_cron
- nova_scheduler
- nova_vnc_proxy
- nova_api
- nova_metadata
- neutron_api
- gnocchi_api
- keystone
- heat_api
- heat_engine
- heat_api_cron
- heat_api_cfn
ignore_errors: yes
when: ('Controller' in group_names and sqlalchemy_collectd_plugin)
# CephStorage OSD monitoring
# Only Monitors a single OSD on each CephStorage Node
- name: Get 1st OSD socket
shell: ls /var/run/ceph/ceph-osd.*.asok | head -n 1 | egrep -o '[0-9]+'
register: cephstorage_osd_socket
become: true
when: "('CephStorage' in group_names and ceph_storage_collectd_plugin)"
# End CephStorage OSD monitoring
- name: Create configuration directory
file:
path: "{{ browbeat_containers_path }}/collectd-openstack/config"
state: directory
- name: Configure collectd.conf
template:
src: "{{ config_type }}.collectd.conf.j2"
dest: "{{ browbeat_containers_path }}/collectd-openstack/config/collectd.conf"
when: "config_type != 'compute'"
- name: Configure compute collectd.conf
template:
src: "{{ config_type }}.collectd.conf.j2"
dest: "{{ browbeat_containers_path }}/collectd-openstack/config/collectd.conf"
when: "config_type == 'compute' and not ovn_compute_collectd_plugin"
- name: Configure compute collectd.conf
template:
src: "ovn_compute.collectd.conf.j2"
dest: "{{ browbeat_containers_path }}/collectd-openstack/config/collectd.conf"
when: "config_type == 'compute' and ovn_compute_collectd_plugin"
- name: Create pipe for to use pcs cli inside collectd container
shell: |
sudo mkfifo /home/"{{ host_remote_user }}"/collectd_pipe
become: yes
become_user: root
ignore_errors: yes
when: "config_type == 'controller' and pacemaker_monitoring"
- name: Create script to run eval on pcs pipe
file:
path: "/home/{{ host_remote_user }}/collectd_pipe_eval.sh"
state: touch
mode: 0775
owner: root
become: yes
become_user: root
ignore_errors: yes
when: "config_type == 'controller' and pacemaker_monitoring"
- name: Add content to script to run eval on pcs pipe
copy:
dest: "/home/{{ host_remote_user }}/collectd_pipe_eval.sh"
content: |
while true; do eval "$(cat /home/{{ host_remote_user }}/collectd_pipe)"; done
become: yes
become_user: root
ignore_errors: yes
when: "config_type == 'controller' and pacemaker_monitoring"
- name: Run script to run eval on pcs pipe
shell: |
nohup ./collectd_pipe_eval.sh > /var/log/containers/stdouts/collectd_pacemaker.out 2>&1 &
become: yes
become_user: root
ignore_errors: yes
args:
chdir: "/home/{{ host_remote_user }}"
when: "config_type == 'controller' and pacemaker_monitoring"
- name: Build and Run container
block:
- name: Build collectd-openstack container
shell: |
{{ container_cli }} build -t collectd-openstack {{ browbeat_containers_path }}/collectd-openstack/
become: true
- name: Run collectd-openstack container
shell: |
{{ container_cli }} rm -f collectd-{{ config_type }}
{{ container_cli }} run --name collectd-{{ config_type }} \
--network host --pid host \
--privileged -d \
-v /var/log/containers:/var/log/containers \
-v /dev:/dev \
{% if config_type == 'controller' or config_type == 'undercloud' %}
-v /var/lib/mysql/mysql.sock:/var/lib/mysql/mysql.sock \
{% endif %}
{% if config_type == 'controller' or config_type == 'compute' %}
{% if ovs_flows_monitoring %}
-v /etc/openvswitch/:/etc/openvswitch/ -v /var/run/openvswitch/:/var/run/openvswitch/ \
{% endif %}
{% endif %}
{% if config_type == 'controller' %}
{% if ovn_monitoring %}
-v /var/lib/openvswitch/ovn/ovnnb_db.sock:/var/lib/openvswitch/ovn/ovnnb_db.sock \
-v /var/lib/openvswitch/ovn/ovnsb_db.sock:/var/lib/openvswitch/ovn/ovnsb_db.sock \
{% endif %}
{% if pacemaker_monitoring %}
-v /home/{{ host_remote_user }}/collectd_pipe:/collectd_pipe \
{% endif %}
{% endif %}
{% if config_type == 'controller' or config_type == 'cephstorage' %}
{% if ceph_controller_collectd_plugin or ceph_storage_collectd_plugin %}
-v /etc/ceph/:/etc/ceph/ -v /var/run/ceph/:/var/run/ceph/ \
{% endif %}
{% endif %}
collectd-openstack
become: yes
- name: Add stack user to wheel
shell: |
podman exec -it -u root collectd-controller usermod -G wheel stack
become: yes
become_user: root
when: "config_type == 'controller' and ovn_monitoring"