From 8d2caac546cc6e57a33b8689b2e0135e55882701 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Wed, 17 Aug 2016 18:57:36 +0100 Subject: [PATCH] Restrict Ansible fact gathering to base subset In Ansible 2.x the fact gathering process includes facts gathered by facter [1] and ohai [2]if they are available. While this may be useful in some environment, OpenStack-Ansible does not make use of any of these facts in any of its playbooks/roles and the facts gathered are therefore just an extra overhead. This patch removes the facter and aohai gathering subsets. On a test AIO this reduced the execution time for fact gathering to the host and all running containers from 1m5s to 6s. [1] https://docs.puppet.com/facter/ [2] https://docs.chef.io/ohai.html This patch also re-implements the selective fact gathering in run-playbooks that was implemented in I348a4b7dfe70d56a64899246daf65ea834a75d2a but unintentionally removed in 9be0662c4f79783d4db8736b89bbd38063635067 Change-Id: I9bfee53571f3dc3a0b0a0950242008e815722180 --- playbooks/ansible.cfg | 1 + playbooks/repo-build.yml | 2 +- scripts/run-playbooks.sh | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/playbooks/ansible.cfg b/playbooks/ansible.cfg index d004a99694..8f7198b6b6 100644 --- a/playbooks/ansible.cfg +++ b/playbooks/ansible.cfg @@ -12,6 +12,7 @@ library = /etc/ansible/roles/plugins/library # Fact caching gathering = smart +gather_subset = !facter,!ohai fact_caching = jsonfile fact_caching_connection = /etc/openstack_deploy/ansible_facts fact_caching_timeout = 86400 diff --git a/playbooks/repo-build.yml b/playbooks/repo-build.yml index 6f169a4038..d83fc16164 100644 --- a/playbooks/repo-build.yml +++ b/playbooks/repo-build.yml @@ -25,7 +25,7 @@ # repo_all[0] is built last to ensure it has all build artifacts for final indexing - name: Build new repo packages for a given release hosts: repo_all[1:],repo_all[0] - gather_facts: true + gather_facts: "{{ gather_facts | default(True) }}" user: root serial: 1 pre_tasks: diff --git a/scripts/run-playbooks.sh b/scripts/run-playbooks.sh index 397e46c51d..c56a6e3ada 100755 --- a/scripts/run-playbooks.sh +++ b/scripts/run-playbooks.sh @@ -45,7 +45,19 @@ If you ever have any questions please join the community conversation on IRC at } function playbook_run { + + # First we gather facts about the hosts to populate the fact cache. + # We can't gather the facts for all hosts yet because the containers + # aren't built yet. + ansible -m setup -a "gather_subset=!facter,!ohai" hosts + for root_include in $(awk -F'include:' '{print $2}' setup-everything.yml); do + # Once setup-hosts is complete, we should gather facts for everything + # (now including containers) so that the fact cache is complete for the + # remainder of the run. + if [[ "${root_include}" == "setup-infrastructure.yml" ]]; then + ansible -m setup -a "gather_subset=!facter,!ohai" all + fi for include in $(awk -F'include:' '{print $2}' "${root_include}"); do echo "[Executing \"${include}\" playbook]" if [[ "${DEPLOY_AIO}" = true ]] && [[ "${include}" == "security-hardening.yml" ]]; then