-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Ansible profile_tasks plugin for timing tasks
- Loading branch information
Showing
11 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Changelog 0.7 | ||
|
||
## [0.7.0] 2020-0X-XX | ||
|
||
### Added | ||
|
||
#### General | ||
|
||
- [#811](https://github.com/epiphany-platform/epiphany/issues/811) - Measure execution time of Ansible tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
core/src/epicli/cli/engine/ansible/AnsibleConfigFileCreator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
from cli.helpers.build_saver import get_ansible_config_file_path, save_ansible_config_file | ||
from cli.helpers.Step import Step | ||
from collections import OrderedDict | ||
|
||
class AnsibleConfigFileCreator(Step): | ||
def __init__(self, ansible_options, cluster_model): | ||
super().__init__(__name__) | ||
self.ansible_options = ansible_options | ||
cluster_name = cluster_model.specification.name | ||
self.ansible_config_file_path = get_ansible_config_file_path(cluster_name) | ||
self.ansible_config_file_settings = OrderedDict() | ||
|
||
def __enter__(self): | ||
super().__enter__() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
super().__exit__(exc_type, exc_value, traceback) | ||
|
||
def get_setting(self, section, key): | ||
setting = None | ||
if section in self.ansible_config_file_settings: | ||
setting = self.ansible_config_file_settings[section].get(key) | ||
return setting | ||
|
||
def add_setting(self, section, key, value): | ||
if section not in self.ansible_config_file_settings: | ||
self.ansible_config_file_settings[section] = {} | ||
if key not in self.ansible_config_file_settings[section]: | ||
self.ansible_config_file_settings[section].update({key: value}) | ||
else: | ||
raise TypeError(f"Setting {section}[{key}] already exists") | ||
|
||
def update_setting(self, section, key, value, append=False): | ||
if (section not in self.ansible_config_file_settings or | ||
key not in self.ansible_config_file_settings[section]): | ||
self.add_setting(section, key, value) | ||
else: | ||
if type(self.ansible_config_file_settings[section][key]) is list and append: | ||
self.ansible_config_file_settings[section][key].append(value) | ||
else: | ||
self.ansible_config_file_settings[section][key] = value | ||
|
||
def process_ansible_options(self): | ||
callback_whitelist = [] | ||
if self.ansible_options['profile_tasks']: | ||
callback_whitelist = ['profile_tasks'] | ||
self.add_setting('defaults', 'callback_whitelist', callback_whitelist) | ||
|
||
def create(self): | ||
self.logger.info('Creating ansible.cfg') | ||
self.process_ansible_options() | ||
save_ansible_config_file(self.ansible_config_file_settings, self.ansible_config_file_path) | ||
os.environ["ANSIBLE_CONFIG"] = self.ansible_config_file_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Ansible configuration file - automated so do not modify | ||
# | ||
|
||
# Ansible will read ANSIBLE_CONFIG, ansible.cfg in the current working directory, | ||
# ansible.cfg in the home directory, or /etc/ansible/ansible.cfg, whichever it finds first. | ||
|
||
# For a full list of available options, run ansible-config list or see the | ||
# documentation: https://docs.ansible.com/ansible/latest/reference_appendices/config.html. | ||
|
||
{% for section in ansible_config_file_settings.keys() -%} | ||
[{{ section }}] | ||
{% for key, value in ansible_config_file_settings[section].items() -%} | ||
{{ key }} = {{ value|join(', ') if (value is sequence and value is not string) else value }} | ||
{% endfor -%} | ||
{% if not loop.last %}{{ '\n' }}{% endif -%} | ||
{% endfor -%} |
This file was deleted.
Oops, something went wrong.