From 4ec57c60f30f994d8bf36021ff12670e6c8c77b5 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Wed, 3 Jul 2019 19:02:20 -0600 Subject: [PATCH] Add facter cache for container configurations Rather than running all the facts for every invocation of container-puppet.py, let's cache the facts for the entire container config step. This is similar to what used to happen when we ran puppet in a single instance for a given step. This improves the time it takes puppet tp execute within the containers. When systems have large number of interfaces, the fact generation for puppet can come to a crawl given that puppet is not supposed to be invoked multiple times in parallel. By pre-caching the facts, we eliminate the need for puppet to do the network (and other fact) related lookups when running container configuration generation. Closes-Bug: #1835959 Change-Id: I6ee3849ff380304a184638493f33882b813bfdff --- common/container-puppet.py | 3 ++ common/deploy-steps-tasks.yaml | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/common/container-puppet.py b/common/container-puppet.py index 91266c2b5e..9ad7c1a883 100755 --- a/common/container-puppet.py +++ b/common/container-puppet.py @@ -436,6 +436,9 @@ def mp_puppet_config(*args): '--volume', '/etc/pki/tls/certs/ca-bundle.trust.crt:/etc/pki/tls/certs/ca-bundle.trust.crt:ro', '--volume', '/etc/pki/tls/cert.pem:/etc/pki/tls/cert.pem:ro', '--volume', '%s:/var/lib/config-data/:rw' % config_volume_prefix, + # facter caching + '--volume', '/var/lib/container-puppet/puppetlabs/facter.conf:/etc/puppetlabs/facter/facter.conf:ro', + '--volume', '/var/lib/container-puppet/puppetlabs/:/opt/puppetlabs/:ro', # Syslog socket for puppet logs '--volume', '/dev/log:/dev/log:rw'] if privileged: diff --git a/common/deploy-steps-tasks.yaml b/common/deploy-steps-tasks.yaml index 3b878aa385..e5b3d2250e 100644 --- a/common/deploy-steps-tasks.yaml +++ b/common/deploy-steps-tasks.yaml @@ -421,6 +421,60 @@ - host_config ignore_errors: "{{ ansible_check_mode|bool }}" + ######################################### + # Pre-cache facts for container-puppet.py + ######################################### + + - name: Create puppet caching structures + file: + path: /var/lib/container-puppet/puppetlabs + state: directory + setype: svirt_sandbox_file_t + selevel: s0 + recurse: True + tags: + - container_config + - container_config_tasks + - name: Write facter cache config + copy: + dest: /var/lib/container-puppet/puppetlabs/facter.conf + content: | + facts : { + ttls: [ + { "kernel" : 8 hour }, + { "memory" : 8 hour }, + { "networking" : 8 hour }, + { "operating system" : 8 hour }, + { "processor" : 8 hour }, + ] + } + tags: + - container_config + - container_config_tasks + - name: Cleanup facter cache if exists + file: + path: /opt/puppetlabs/facter + state: absent + ignore_errors: True + tags: + - container_config + - container_config_tasks + - name: Pre-cache facts + command: facter --config /var/lib/container-puppet/puppetlabs/facter.conf + no_log: True + ignore_errors: True + tags: + - container_config + - container_config_tasks + - name: Sync cached facts + synchronize: + src: /opt/puppetlabs/ + dest: /var/lib/container-puppet/puppetlabs/ + delegate_to: "{{ inventory_hostname }}" + tags: + - container_config + - container_config_tasks + ###################################### # Generate config via container-puppet.py ######################################