Allow collectd-openstack tasks to run without a controller

Several errors would occur if you attempted to run this playbook without
a controller group or controller under the controller group.  This commit
resolves both by ensuring each group actually exists and the when statements
in Ansible to short-circuit before attempting to get groups['controller'][0]

Change-Id: I8ee493f9660c05e391e991908511f94e7d432bc1
This commit is contained in:
akrzos 2018-01-10 08:39:11 -05:00 committed by Alex Krzos
parent e56bba79b8
commit 13ebab3030
2 changed files with 20 additions and 20 deletions

View File

@ -246,37 +246,37 @@ fi
echo "" | tee -a ${ansible_inventory_file}
echo "[undercloud]" | tee -a ${ansible_inventory_file}
echo "undercloud" | tee -a ${ansible_inventory_file}
echo "" | tee -a ${ansible_inventory_file}
echo "[controller]" | tee -a ${ansible_inventory_file}
if [[ ${#controller_hn} -gt 0 ]]; then
echo "" | tee -a ${ansible_inventory_file}
echo "[controller]" | tee -a ${ansible_inventory_file}
for ct in ${controller_hn[@]}; do
echo "${ct}" | tee -a ${ansible_inventory_file}
done
fi
echo "" | tee -a ${ansible_inventory_file}
echo "[blockstorage]" | tee -a ${ansible_inventory_file}
if [[ ${#blockstorage_hn} -gt 0 ]]; then
echo "" | tee -a ${ansible_inventory_file}
echo "[blockstorage]" | tee -a ${ansible_inventory_file}
for blockstorage in ${blockstorage_hn[@]}; do
echo "${blockstorage}" | tee -a ${ansible_inventory_file}
done
fi
echo "" | tee -a ${ansible_inventory_file}
echo "[objectstorage]" | tee -a ${ansible_inventory_file}
if [[ ${#objectstorage_hn} -gt 0 ]]; then
echo "" | tee -a ${ansible_inventory_file}
echo "[objectstorage]" | tee -a ${ansible_inventory_file}
for objectstorage in ${objectstorage_hn[@]}; do
echo "${objectstorage}" | tee -a ${ansible_inventory_file}
done
fi
echo "" | tee -a ${ansible_inventory_file}
echo "[cephstorage]" | tee -a ${ansible_inventory_file}
if [[ ${#cephstorage_hn} -gt 0 ]]; then
echo "" | tee -a ${ansible_inventory_file}
echo "[cephstorage]" | tee -a ${ansible_inventory_file}
for cephstorage in ${cephstorage_hn[@]}; do
echo "${cephstorage}" | tee -a ${ansible_inventory_file}
done
fi
echo "" | tee -a ${ansible_inventory_file}
echo "[compute]" | tee -a ${ansible_inventory_file}
if [[ ${#compute_hn} -gt 0 ]]; then
echo "" | tee -a ${ansible_inventory_file}
echo "[compute]" | tee -a ${ansible_inventory_file}
for c in ${compute_hn[@]}; do
echo "${c}" | tee -a ${ansible_inventory_file}
done
@ -300,9 +300,9 @@ if [[ ${#controller_hn} -gt 0 ]] || [[ ${#blockstorage_hn} -gt 0 ]] || [[ ${#obj
echo "compute" | tee -a ${ansible_inventory_file}
fi
fi
echo "" | tee -a ${ansible_inventory_file}
echo "[other]" | tee -a ${ansible_inventory_file}
if [[ ${#other_hn} -gt 0 ]]; then
echo "" | tee -a ${ansible_inventory_file}
echo "[other]" | tee -a ${ansible_inventory_file}
for other in ${other_hn[@]}; do
echo "${other}" | tee -a ${ansible_inventory_file}
done

View File

@ -115,7 +115,7 @@
shell: "cat /home/stack/overcloudrc | grep 'export OS' | awk '{gsub(/export /,\"Environment=\");print }'"
delegate_to: "{{groups['undercloud'][0]}}"
register: overcloudrc_file
when: "(gnocchi_status_controller_collectd_plugin == true) and (inventory_hostname == groups['controller'][0])"
when: "'controller' in group_names and gnocchi_status_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]"
- name: (Controller) Add environment variables to collectd.service systemd file
become: true
@ -124,7 +124,7 @@
insertafter: '\[Service\]'
line: "{{item}}"
with_items: "{{overcloudrc_file.stdout_lines | default(omit)}}"
when: "(gnocchi_status_controller_collectd_plugin == true) and (inventory_hostname == groups['controller'][0])"
when: "'controller' in group_names and gnocchi_status_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]"
# Apache Request Response Timing
- name: (Newton, Ocata) Deploy Apache httpd.conf for request timings
@ -195,7 +195,7 @@
- name: Reload systemd units
command: systemctl daemon-reload
become: true
when: "((gnocchi_status_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]) or ('undercloud' in group_names and {{gnocchi_status_undercloud_collectd_plugin}} == true))"
when: "('controller' in group_names and gnocchi_status_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]) or ('undercloud' in group_names and gnocchi_status_undercloud_collectd_plugin == true)"
- name: (All Nodes) Copy python plugins
copy:
@ -274,14 +274,14 @@
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}} == true and '{{inventory_hostname}}' == groups['controller'][0])"
when: "'controller' in group_names and rabbitmq_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]"
# Works with: Newton, Ocata
- 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}} == true and '{{inventory_hostname}}' == groups['controller'][0])"
when: "'controller' in group_names and rabbitmq_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]"
# End Rabbitmq monitoring
# Gnocchi Swift Stat Service monitoring
@ -289,19 +289,19 @@
command: hiera -c /etc/puppet/hiera.yaml gnocchi::storage::swift::swift_authurl
register: controller0_gnocchi_swift_authurl
become: true
when: "('controller' in group_names and {{swift_stat_controller_collectd_plugin}} == true and '{{inventory_hostname}}' == groups['controller'][0])"
when: "'controller' in group_names and swift_stat_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]"
- name: Get Gnocchi Swift User
shell: hiera -c /etc/puppet/hiera.yaml gnocchi::storage::swift::swift_user | sed 's/service://'
register: controller0_gnocchi_swift_user
become: true
when: "('controller' in group_names and {{swift_stat_controller_collectd_plugin}} == true and '{{inventory_hostname}}' == groups['controller'][0])"
when: "'controller' in group_names and swift_stat_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]"
- name: Get Gnocchi Swift Key
command: hiera -c /etc/puppet/hiera.yaml gnocchi::storage::swift::swift_key
register: controller0_gnocchi_swift_auth_key
become: true
when: "('controller' in group_names and {{swift_stat_controller_collectd_plugin}} == true and '{{inventory_hostname}}' == groups['controller'][0])"
when: "'controller' in group_names and swift_stat_controller_collectd_plugin == true and inventory_hostname == groups['controller'][0]"
# End Swift Stat Service monitoring
# CephStorage OSD monitoring