Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ejbca shell module to Ansible playbooks #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"cSpell.words": [
"basenames",
"blockinfile",
"insertafter",
"lineinfile",
"outfile",
"splitext"
]
}
13 changes: 12 additions & 1 deletion ansible_ejbca_signsrv/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ inventory = ./inventory
fact_caching = jsonfile
fact_caching_connection = ~/ansible/ansibleCacheDir
fact_caching_timeout = 86400
collections_paths = ./ansible_collections

ansible_managed = This file is managed by Ansible.%n
template: {file}
Expand All @@ -13,5 +14,15 @@ ansible_managed = This file is managed by Ansible.%n

# Use the YAML callback plugin.
stdout_callback = yaml
#stdout_callback = json
# Use the stdout_callback when running ad-hoc commands.
bin_ansible_callbacks = True
bin_ansible_callbacks = True

localhost_warning = false
action_warnings = false
system_warnings = false
#interpreter_python= /usr/bin/python3.9
interpreter_python = auto_silent



Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ansible Collection - ejbca.utils

Documentation for the collection.
56 changes: 56 additions & 0 deletions ansible_ejbca_signsrv/ansible_collections/ejbca/manage/galaxy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
### REQUIRED
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
# content lives. May only contain alphanumeric lowercase characters and underscores. Namespaces cannot start with
# underscores or numbers and cannot contain consecutive underscores
namespace: jtgarner_keyfactor

# The name of the collection. Has the same character restrictions as 'namespace'
name: ejbca

# The version of the collection. Must be compatible with semantic versioning
version: 1.0.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md

# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
# @nicks:irc/im.site#channel'
authors:
- Jamie Garner <[email protected]>

### OPTIONAL but strongly recommended
# A short summary description of the collection
description: Contains modules to assist with running EJBCA and SignServer Enterprise and Community playbooks.

# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
license:
- GPL-2.0-or-later

# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
# requirements as 'namespace' and 'name'
tags:
- keyfactor
- ejbca

# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
# collection label 'namespace.name'. The value is a version range
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
# range specifiers can be set and are separated by ','
dependencies: {}

# The URL of the originating SCM repository
repository: https://github.com/Keyfactor/automated-ansible-documentation

# The URL to any online docs
documentation: https://github.com/Keyfactor/ansible-ejbca-signserver-playbooks/wiki

# The URL to the collection issue tracker
issues: https://github.com/Keyfactor/ansible-ejbca-signserver-playbooks/issues

# A list of file glob-like patterns used to filter any files or directories that should not be included in the build
# artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This
# uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry',
# and '.git' are always filtered
build_ignore: []

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Collections Plugins Directory

This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that
is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that
would contain module utils and modules respectively.

Here is an example directory of the majority of plugins currently supported by Ansible:

```
└── plugins
├── action
├── become
├── cache
├── callback
├── cliconf
├── connection
├── filter
├── httpapi
├── inventory
├── lookup
├── module_utils
├── modules
├── netconf
├── shell
├── strategy
├── terminal
├── test
└── vars
```

A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible-core/2.12/plugins/plugins.html).
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/python

import re

class FilterModule(object):
def filters(self):
return {
'acronym': self.acronym,
'selection': self.selection,
'yesno': self.yesno,
'columnwidth': self.columnwidth,
'common': self.common,
'validlist': self.validlist,
'logical': self.logical,
'slugify': self.slugify,
}

def acronym(self, str:str):
acronym = ""
words = str.split()
for word in words:
acronym += word[0].upper()
return acronym

def selection(self, choice:int):
""" Returns True or False value for integer """
if choice == 1:
return True
else:
return False

def yesno(self, boolean:bool):
""" Returns Yes or No value for boolean """
if boolean:
return 'Yes'
else:
return 'No'

def columnwidth(self, list:list, max_width=80, stub_width=15):
""" Dynamically sets ReStructured table columb width based on list length """
columns = len(list)
remaining_width = max_width - stub_width
if columns > 1:
length = remaining_width // columns
column_width = str()
for i in range(len(list)):
column_width += f' {length}'
total_width = str(stub_width) + column_width

else:
total_width = str(f'{stub_width} {remaining_width}')

return total_width

def validlist(self, list:list):
""" Checks if list is not empty, and length is greater than 0 """
if list != None and len(list) > 0:
return True
return False

def common(self, str:str):
str = str.strip()
str = re.sub(r'[^\w\s-]', ' ', str)
str = re.sub(r'[\s_-]+', ' ', str)
str = re.sub(r'^-+|-+$', ' ', str)
return str

def logical(self, str:str):
str = str.strip()
str = re.sub(r'[^\w\s-]', '', str)
str = re.sub(r'[\s_-]+', '-', str)
str = re.sub(r'^-+|-+$', '', str)
return str

def slugify(self, str:str):
str = str.lower().strip()
str = re.sub(r'[^\w\s-]', '', str)
str = re.sub(r'[\s_-]+', '-', str)
str = re.sub(r'^-+|-+$', '', str)
return str






Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python

from __future__ import absolute_import, division, print_function
__metaclass__ = type

import re
import yaml

def import_yaml(yaml_file:str):
""" Import yaml file and creates temporary dictionary """

# initialize dict
imported_vars_dict = dict()

with open(yaml_file, 'r') as file:
imported_file = yaml.safe_load(file)
for key,value in imported_file.items() if imported_file != None else {}:
imported_vars_dict[key] = value

file.close()

return imported_vars_dict

def output_yaml(yaml_file:str, dictionary:dict, append:bool = False, write:bool = True):
""" Output yaml file from dictionary """

with open(yaml_file, 'w') as file:
yaml.dump(dictionary, file)
Loading