From 5d2fc799e2702d7eae1a22564e9ac4e7afdfbc55 Mon Sep 17 00:00:00 2001 From: DO1JLR Date: Sat, 5 May 2018 01:44:57 +0200 Subject: [PATCH] Initialize Ansible --- .gitmodules | 12 ++ README.md | 4 + ansible.cfg | 14 +++ ansible/callback_plugins/human_log.py | 147 +++++++++++++++++++++++++ ansible/callback_plugins/human_log.pyc | Bin 0 -> 6339 bytes ansible/hosts | 2 + ansible/lookup_plugin | 1 + roles/common | 1 + roles/ssh_authorized_keys | 1 + roles/sshd | 1 + setup_apu3.yml | 9 ++ 11 files changed, 192 insertions(+) create mode 100644 .gitmodules create mode 100644 ansible.cfg create mode 100644 ansible/callback_plugins/human_log.py create mode 100644 ansible/callback_plugins/human_log.pyc create mode 100644 ansible/hosts create mode 160000 ansible/lookup_plugin create mode 160000 roles/common create mode 160000 roles/ssh_authorized_keys create mode 160000 roles/sshd create mode 100644 setup_apu3.yml diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9ff6b9f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "ansible/lookup_plugin"] + path = ansible/lookup_plugin + url = git@git.ccczh.ch:ansible-roles/plugin-hostfiles.git +[submodule "roles/common"] + path = roles/common + url = git@git.ccczh.ch:ansible-roles/role-base_packages.git +[submodule "roles/ssh_authorized_keys"] + path = roles/ssh_authorized_keys + url = git@git.ccczh.ch:ansible-roles/role-ssh_authorized_keys.git +[submodule "roles/sshd"] + path = roles/sshd + url = git@git.ccczh.ch:ansible-roles/role-sshd.git diff --git a/README.md b/README.md index e69de29..a61993f 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,4 @@ + APU3 with LTE +================ + +Here you will find the Ansible Playbook to setup a apu3 with LTE... diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..258f4c1 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,14 @@ +[defaults] + +callback_plugins = ansible/callback_plugins +lookup_plugins = ansible/lookup_plugin +inventory = ./ansible/hosts +remote_user = root +retry_files_enabled = False +nocows = True + +# [privilege_escalation] +# become=Yes +# become_method=sudo +# become_user=root +# become_ask_pass=False diff --git a/ansible/callback_plugins/human_log.py b/ansible/callback_plugins/human_log.py new file mode 100644 index 0000000..b2e7701 --- /dev/null +++ b/ansible/callback_plugins/human_log.py @@ -0,0 +1,147 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Inspired from: https://gist.github.com/cliffano/9868180 +# Improved and made compatible with Ansible v2 + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.callback import CallbackBase +try: + import simplejson as json +except ImportError: + import json + +# Fields to reformat output for +FIELDS = ['cmd', 'command', 'start', 'end', 'delta', 'msg', 'stdout', + 'stderr', 'results'] + + +class CallbackModule(CallbackBase): + def human_log(self, data): + if type(data) == dict: + for field in FIELDS: + if field in data.keys() and data[field]: + output = self._format_output(data[field]) + print("\n{0}: {1}".format(field, output.replace("\\n","\n")).strip()) + + def _format_output(self, output): + # Strip unicode + if type(output) == unicode: + output = output.encode('ascii', 'replace') + + # If output is a dict + if type(output) == dict: + return json.dumps(output, indent=2) + + # If output is a list of dicts + if type(output) == list and type(output[0]) == dict: + # This gets a little complicated because it potentially means + # nested results, usually because of with_items. + real_output = list() + for index, item in enumerate(output): + copy = item + if type(item) == dict: + for field in FIELDS: + if field in item.keys(): + copy[field] = self._format_output(item[field]) + real_output.append(copy) + return json.dumps(output, indent=2) + + # If output is a list of strings + if type(output) == list and type(output[0]) != dict: + # Strip newline characters + real_output = list() + for item in output: + if "\n" in item: + for string in item.split("\n"): + real_output.append(string) + else: + real_output.append(item) + + # Reformat lists with line breaks only if the total length is + # >75 chars + if len("".join(real_output)) > 75: + return "\n" + "\n".join(real_output) + else: + return " ".join(real_output) + + # Otherwise it's a string, just return it + return output + + def on_any(self, *args, **kwargs): + pass + + def runner_on_failed(self, host, res, ignore_errors=False): + self.human_log(res) + + def runner_on_ok(self, host, res): + self.human_log(res) + + + def runner_on_error(self, host, msg): + pass + + def runner_on_skipped(self, host, item=None): + pass + + def runner_on_unreachable(self, host, res): + self.human_log(res) + + def runner_on_no_hosts(self): + pass + + def runner_on_async_poll(self, host, res, jid, clock): + self.human_log(res) + + def runner_on_async_ok(self, host, res, jid): + self.human_log(res) + + def runner_on_async_failed(self, host, res, jid): + self.human_log(res) + + def playbook_on_start(self): + pass + + def playbook_on_notify(self, host, handler): + pass + + def playbook_on_no_hosts_matched(self): + pass + + def playbook_on_no_hosts_remaining(self): + pass + + def playbook_on_task_start(self, name, is_conditional): + pass + + def playbook_on_vars_prompt(self, varname, private=True, prompt=None, + encrypt=None, confirm=False, salt_size=None, + salt=None, default=None): + pass + + def playbook_on_setup(self): + pass + + def playbook_on_import_for_host(self, host, imported_file): + pass + + def playbook_on_not_import_for_host(self, host, missing_file): + pass + + def playbook_on_play_start(self, pattern): + pass + + def playbook_on_stats(self, stats): + pass diff --git a/ansible/callback_plugins/human_log.pyc b/ansible/callback_plugins/human_log.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c7867ab14a7a41ac57e9ba9e337a7edf01ab20f1 GIT binary patch literal 6339 zcmdT|TW=f36+XkINKuw#T`W6_-PX-Z_z+l4(rcQefvu!)n<~jFtr{Z2dc8BGmfV|n zhK^WUy&y(_76l6Qy+0$rpeXtS`p|#ThxQNjd}m3KQ4*u7i6)hHhiA{u%zo$0cg|eA zf2}P2^}=5|5sm*^{QKG+MfOiDXucFBM5&^VqO?Yx8l@g}JW{4kodu~;qohG;lR8aO zqcu@^lq^!GMF-hesBV^Muta4@N-6ZnFI#w-Df+ptljdF;q?@D{Nw-KZk-k8BnR;A_ zg%vVQ>MGK!^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