Feature to ignore Ansible files based on patterns.

Change-Id: If905a0d0054acfcbc16aab993e9c669dc9ee41cd
This commit is contained in:
Laurent Dumont 2020-01-19 00:40:07 -05:00 committed by David Moreau Simard
parent ad8803318f
commit 23aaffb83c
2 changed files with 27 additions and 7 deletions

3
.gitignore vendored
View File

@ -82,6 +82,9 @@ celerybeat-schedule
# dotenv # dotenv
.env .env
# vscode stuff
.vscode
# virtualenv # virtualenv
.venv/ .venv/
venv/ venv/

View File

@ -132,6 +132,15 @@ options:
ini: ini:
- section: ara - section: ara
key: ignored_arguments key: ignored_arguments
ignored_files:
description: List of patterns that will not be saved by ARA
type: list
default: []
env:
- name: ARA_IGNORED_FILES
ini:
- section: ara
key: ignored_files
""" """
@ -150,6 +159,7 @@ class CallbackModule(CallbackBase):
self.client = None self.client = None
self.ignored_facts = [] self.ignored_facts = []
self.ignored_arguments = [] self.ignored_arguments = []
self.ignored_files = []
self.result = None self.result = None
self.task = None self.task = None
@ -166,6 +176,7 @@ class CallbackModule(CallbackBase):
self.default_labels = self.get_option("default_labels") self.default_labels = self.get_option("default_labels")
self.ignored_facts = self.get_option("ignored_facts") self.ignored_facts = self.get_option("ignored_facts")
self.ignored_arguments = self.get_option("ignored_arguments") self.ignored_arguments = self.get_option("ignored_arguments")
self.ignored_files = self.get_option("ignored_files")
client = self.get_option("api_client") client = self.get_option("api_client")
endpoint = self.get_option("api_server") endpoint = self.get_option("api_server")
@ -335,13 +346,19 @@ class CallbackModule(CallbackBase):
def _get_or_create_file(self, path): def _get_or_create_file(self, path):
if path not in self.file_cache: if path not in self.file_cache:
self.log.debug("File not in cache, getting or creating: %s" % path) self.log.debug("File not in cache, getting or creating: %s" % path)
try: content = None
with open(path, "r") as fd: for ignored_file_pattern in self.ignored_files:
content = fd.read() if ignored_file_pattern in path:
except IOError as e: self.log.debug("Ignoring file {1}, matched pattern: {0}".format(ignored_file_pattern, path))
self.log.error("Unable to open {0} for reading: {1}".format(path, six.text_type(e))) content = "Not saved by ARA as configured by 'ignored_files'"
content = """ARA was not able to read this file successfully. if content is None:
Refer to the logs for more information""" try:
with open(path, "r") as fd:
content = fd.read()
except IOError as e:
self.log.error("Unable to open {0} for reading: {1}".format(path, six.text_type(e)))
content = """ARA was not able to read this file successfully.
Refer to the logs for more information"""
self.file_cache[path] = self.client.post( self.file_cache[path] = self.client.post(
"/api/v1/files", playbook=self.playbook["id"], path=path, content=content "/api/v1/files", playbook=self.playbook["id"], path=path, content=content