diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..3823df5 --- /dev/null +++ b/README.rst @@ -0,0 +1,42 @@ +================== +ansible-role-boto3 +================== + +Ansible role to install AWS's boto3 library + +* License: Apache License, Version 2.0 +* Documentation: https://ansible-role-boto3.readthedocs.org +* Source: https://git.openstack.org/cgit/openstack/ansible-role-boto3 +* Bugs: https://bugs.launchpad.net/ansible-role-boto3 + +Description +----------- + +AWS's boto3 is a simple client library for operating AWS. + +Requirements +------------ + +See `bindep.txt` for role dependencies. + +Packages +~~~~~~~~ + +Package repository index files should be up to date before using this role, we +do not manage them. + +Role Variables +-------------- + +Dependencies +------------ + +Example Playbook +---------------- + +.. code-block:: yaml + + - name: Install AWS's Boto3 lib + hosts: nodepool + roles: + - ansible-role-boto3 diff --git a/bindep.txt b/bindep.txt new file mode 100644 index 0000000..a07f209 --- /dev/null +++ b/bindep.txt @@ -0,0 +1,9 @@ +# This is a cross-platform list tracking distribution packages needed by tests; +# see http://docs.openstack.org/infra/bindep/ for additional information. + +git +libffi-devel [platform:rpm] +libffi-dev [platform:dpkg] +libssl-dev [platform:dpkg] +openssl-devel [platform:rpm] +python2-dnf [platform:fedora] diff --git a/defaults/main.yaml b/defaults/main.yaml new file mode 100644 index 0000000..2a7b975 --- /dev/null +++ b/defaults/main.yaml @@ -0,0 +1,32 @@ +# Copyright 2015-2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +# tasks/main.yaml +boto3_task_manager: + - install + - config + +# tasks/config.yaml +boto3_user_name: root +boto3_user_group: root +boto3_user_home: /root + +boto3_file_credentials_dest: "{{ boto3_user_home }}/.aws/credentials" +boto3_file_credentials_group: "{{ boto3_user_group }}" +boto3_file_credentials_mode: 0640 +boto3_file_credentials_owner: "{{ boto3_user_name }}" +boto3_file_credentials_src: root/.aws/credentials.j2 + +boto3_pip_name: boto3 +# boto3_pip_virtualenv: /root/venv diff --git a/doc/source/conf.py b/doc/source/conf.py new file mode 100755 index 0000000..69c8ccd --- /dev/null +++ b/doc/source/conf.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys + +sys.path.insert(0, os.path.abspath('../..')) +# -- General configuration ---------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = [ + 'sphinx.ext.autodoc', +] + +# autodoc generation is a bit aggressive and a nuisance when doing heavy +# text edit cycles. +# execute "export SPHINX_DEBUG=1" in your terminal to disable + +# The suffix of source filenames. +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'ansible-role-openstacksdk' +copyright = u'2013, OpenStack Foundation' + +# If true, '()' will be appended to :func: etc. cross-reference text. +add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +add_module_names = True + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# -- Options for HTML output -------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. Major themes that come with +# Sphinx are currently 'default' and 'sphinxdoc'. +# html_theme_path = ["."] +# html_theme = '_theme' +# html_static_path = ['static'] + +# Output file base name for HTML help builder. +htmlhelp_basename = '%sdoc' % project + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass +# [howto/manual]). +latex_documents = [ + ('index', + '%s.tex' % project, + u'%s Documentation' % project, + u'OpenStack Foundation', 'manual'), +] + +# Example configuration for intersphinx: refer to the Python standard library. +# intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/doc/source/index.rst b/doc/source/index.rst new file mode 100644 index 0000000..a6210d3 --- /dev/null +++ b/doc/source/index.rst @@ -0,0 +1 @@ +.. include:: ../../README.rst diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..1f792fd --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,31 @@ +# Copyright 2015-2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +galaxy_info: + author: Gonéri Le Bouder + description: Boto3 library for AWS + company: Red Hat, Inc. + license: Apache + min_ansible_version: 2.4 + platforms: + - name: Fedora + versions: + - 31 + - name: Ubuntu + versions: + - 18.04 + - 20.04 + categories: + - system +dependencies: [] diff --git a/tasks/config.yaml b/tasks/config.yaml new file mode 100644 index 0000000..d5aa0c2 --- /dev/null +++ b/tasks/config.yaml @@ -0,0 +1,30 @@ +# Copyright 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +- name: Create the .aws + become: true + file: + group: "{{ boto3_user_group }}" + owner: "{{ boto3_user_name }}" + path: "{{ boto3_user_home }}/.aws" + state: directory + +- name: Generate the AWS credentials file + become: true + template: + group: "{{ boto3_user_group }}" + owner: "{{ boto3_user_name }}" + dest: "{{ boto3_user_home }}/.aws/credentials" + mode: "{{ boto3_file_credentials_mode }}" + src: "{{ boto3_file_credentials_src }}" diff --git a/tasks/install.yaml b/tasks/install.yaml new file mode 100644 index 0000000..c233deb --- /dev/null +++ b/tasks/install.yaml @@ -0,0 +1,20 @@ +# Copyright 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +- name: Install boto3 using pip + become: true + become_user: "{{ boto3_user_name }}" + pip: + name: "{{ boto3_pip_name }}" + virtualenv: "{{ boto3_pip_virtualenv|default(omit) }}" diff --git a/tasks/main.yaml b/tasks/main.yaml new file mode 100644 index 0000000..5985618 --- /dev/null +++ b/tasks/main.yaml @@ -0,0 +1,18 @@ +# Copyright 2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +- include: "{{ boto3_task }}.yaml" + with_items: "{{ boto3_task_manager }}" + loop_control: + loop_var: boto3_task diff --git a/templates/root/.aws/credentials.j2 b/templates/root/.aws/credentials.j2 new file mode 100644 index 0000000..131bafe --- /dev/null +++ b/templates/root/.aws/credentials.j2 @@ -0,0 +1 @@ +# Default credentials template diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost diff --git a/tests/playbooks/pre.yaml b/tests/playbooks/pre.yaml new file mode 100644 index 0000000..42ec03d --- /dev/null +++ b/tests/playbooks/pre.yaml @@ -0,0 +1,9 @@ +--- +- hosts: all + tasks: + - name: Disable extra wheels mirror + become: true + lineinfile: + dest: /etc/pip.conf + regexp: ^extra-index-url + state: absent diff --git a/tests/playbooks/run.yaml b/tests/playbooks/run.yaml new file mode 100644 index 0000000..d43a4f5 --- /dev/null +++ b/tests/playbooks/run.yaml @@ -0,0 +1,36 @@ +# Copyright 2015-2020 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +--- +- hosts: all + vars: + rolename: ansible-role-boto3 + + roles: + - "{{ rolename }}" + + post_tasks: + - name: Register aws_credentials_file_stat + become: true + stat: + path: /root/.aws/credentials + register: aws_credentials_file_stat + + - name: Assert aws_credentials_file_stat tests + assert: + that: + - aws_credentials_file_stat.stat.exists + - aws_credentials_file_stat.stat.isreg + - aws_credentials_file_stat.stat.pw_name == 'root' + - aws_credentials_file_stat.stat.gr_name == 'root' + - aws_credentials_file_stat.stat.mode == '0640'