├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── documentation_report.md │ └── feature_request.md └── pull_request_template.md ├── .gitignore ├── .gitlab-ci.yml ├── .travis.yml ├── .yamllint ├── LICENSE ├── README.md ├── ansible-role-{{cookiecutter.role_name}} ├── .ansible-lint ├── .cookiecutter.yml ├── .github │ ├── ISSUE_TEMPLATE │ │ ├── bug_report.md │ │ ├── documentation_report.md │ │ └── feature_request.md │ └── pull_request_template.md ├── .gitignore ├── .gitlab-ci.yml ├── .travis.yml ├── .yamllint ├── LICENSE ├── README.md ├── defaults │ └── main.yml ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── molecule │ ├── cloud-aws-direct │ │ ├── molecule.yml │ │ └── playbook.yml │ ├── cloud-azure-direct │ │ ├── molecule.yml │ │ └── playbook.yml │ ├── cloud-epc-delegated │ │ ├── molecule.yml │ │ └── playbook.yml │ ├── default │ │ ├── Dockerfile.j2 │ │ ├── molecule.yml │ │ └── playbook.yml │ └── resources │ │ └── tests │ │ └── verify.yml ├── requirements.yml ├── tasks │ └── main.yml ├── templates │ └── .gitkeep └── vars │ └── main.yml ├── cookiecutter.json ├── docs ├── _config.yml ├── ansible_code_snippets │ └── ansible_code_snippets.md ├── ansible_style_guide │ └── ansible_style_guide.md └── index.md └── hooks └── post_gen_project.py /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | 13 | 14 | ##### SUMMARY 15 | 16 | 17 | ##### ISSUE TYPE 18 | - Bug Report 19 | 20 | ##### COMPONENT NAME 21 | 23 | 24 | ##### ANSIBLE VERSION 25 | 26 | ``` 27 | 28 | ``` 29 | 30 | ##### CONFIGURATION 31 | 34 | 35 | ##### OS / ENVIRONMENT 36 | 40 | 41 | ##### STEPS TO REPRODUCE 42 | 44 | 45 | 46 | ```yaml 47 | 48 | ``` 49 | 50 | 51 | 52 | ##### EXPECTED RESULTS 53 | 54 | 55 | ##### ACTUAL RESULTS 56 | 57 | 58 | 59 | ``` 60 | 61 | ``` 62 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 📝 Documentation Report 3 | about: Ask us about docs 4 | 5 | --- 6 | 7 | 13 | 14 | ##### SUMMARY 15 | 16 | 17 | ##### ISSUE TYPE 18 | - Documentation Report 19 | 20 | ##### COMPONENT NAME 21 | 23 | 24 | ##### ANSIBLE VERSION 25 | 26 | ``` 27 | 28 | ``` 29 | 30 | ##### CONFIGURATION 31 | 34 | 35 | ##### OS / ENVIRONMENT 36 | 40 | 41 | ##### STEPS TO REPRODUCE 42 | 44 | 45 | 46 | ```yaml 47 | 48 | ``` 49 | 50 | 51 | 52 | ##### EXPECTED RESULTS 53 | 54 | 55 | ##### ACTUAL RESULTS 56 | 57 | 58 | 59 | ``` 60 | 61 | ``` 62 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ✨ Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | 13 | 14 | ##### SUMMARY 15 | 16 | 17 | ##### ISSUE TYPE 18 | - Feature Idea 19 | 20 | ##### COMPONENT NAME 21 | 23 | 24 | ##### ANSIBLE VERSION 25 | 26 | ``` 27 | 28 | ``` 29 | 30 | ##### CONFIGURATION 31 | 34 | 35 | ##### OS / ENVIRONMENT 36 | 40 | 41 | ##### STEPS TO REPRODUCE 42 | 44 | 45 | 46 | ```yaml 47 | 48 | ``` 49 | 50 | 51 | 52 | ##### EXPECTED RESULTS 53 | 54 | 55 | ##### ACTUAL RESULTS 56 | 57 | 58 | 59 | ``` 60 | 61 | ``` 62 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Pull Request Template 2 | 3 | ## Description 4 | 5 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. 6 | 7 | Fixes # (issue) 8 | 9 | ## Type of change 10 | 11 | Please delete options that are not relevant. 12 | 13 | - [ ] Bug fix (non-breaking change which fixes an issue) 14 | - [ ] New feature (non-breaking change which adds functionality) 15 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 16 | - [ ] This change requires a documentation update 17 | 18 | ## Reviews 19 | 20 | Please identify developer to review this change 21 | 22 | - [ ] @developer 23 | 24 | ## Checklist: 25 | 26 | - [ ] I have performed a self-review of my own code 27 | - [ ] I have made corresponding changes to the documentation 28 | - [ ] My changes generate no new warnings 29 | - [ ] I have added tests that prove my fix is effective or that my feature works 30 | - [ ] New and existing tests pass with my changes 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | .pyc 3 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Run all tests 3 | stages: 4 | - lint 5 | - deployment test 6 | 7 | before_script: 8 | - ansible --version 9 | - ansible-lint --version 10 | - molecule --version 11 | 12 | variables: 13 | GET_SOURCES_ATTEMPTS: "5" 14 | 15 | Lint: 16 | stage: lint 17 | before_script: 18 | - git clone https://github.com/lean-delivery/ansible-lint-rules.git ~/ansible-lint-rules 19 | script: 20 | - cookiecutter -f --no-input . 21 | - cd ansible-role-default_role 22 | - yamllint . -c .yamllint 23 | - ansible-lint . -c .ansible-lint 24 | after_script: 25 | - rm -rf ~/ansible-lint-rules 26 | tags: 27 | - lint 28 | 29 | Docker role from cookiecutter test: 30 | stage: deployment test 31 | script: 32 | - cookiecutter -f --no-input . 33 | - cd ansible-role-default_role 34 | - molecule test -s default 35 | tags: 36 | - aws 37 | 38 | AWS role from cookiecutter test: 39 | variables: 40 | AWS_REGION: us-east-1 41 | stage: deployment test 42 | script: 43 | - cookiecutter -f --no-input . 44 | - cd ansible-role-default_role 45 | - git clone https://github.com/lean-delivery/ansible-molecule-drivers.git molecule/resources/provisioning 46 | - molecule test -s cloud-aws-direct 47 | tags: 48 | - aws 49 | 50 | AZURE role from cookiecutter test: 51 | stage: deployment test 52 | script: 53 | - cookiecutter -f --no-input . 54 | - cd ansible-role-default_role 55 | - git clone https://github.com/lean-delivery/ansible-molecule-drivers.git molecule/resources/provisioning 56 | - molecule test -s cloud-azure-direct 57 | tags: 58 | - azure 59 | 60 | .EPC role from cookiecutter test: 61 | variables: 62 | EPC_REGION: EPAM-BY2 63 | stage: deployment test 64 | script: 65 | - cookiecutter -f --no-input . 66 | - cd ansible-role-default_role 67 | - git clone https://github.com/lean-delivery/ansible-molecule-drivers.git molecule/resources/provisioning 68 | - molecule test -s cloud-epc-delegated 69 | tags: 70 | - delegated 71 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dist: bionic 3 | sudo: required 4 | 5 | language: python 6 | python: 7 | - "3.7" 8 | 9 | services: 10 | - docker 11 | 12 | before_install: 13 | - git clone https://github.com/lean-delivery/ansible-lint-rules.git ~/ansible-lint-rules 14 | 15 | install: 16 | - pip3 install --upgrade ansible==2.8.* docker 17 | - pip3 install molecule==2.22 18 | - pip3 install git+https://github.com/ansible/ansible-lint.git 19 | - ansible --version 20 | - ansible-lint --version 21 | 22 | script: 23 | - cookiecutter --no-input . 24 | - cd ansible-role-default_role 25 | - yamllint . -c .yamllint 26 | - ansible-lint . -c .ansible-lint 27 | - molecule test 28 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | braces: 6 | max-spaces-inside: 1 7 | level: error 8 | brackets: 9 | max-spaces-inside: 1 10 | level: error 11 | colons: 12 | max-spaces-after: -1 13 | level: error 14 | commas: 15 | max-spaces-after: -1 16 | level: error 17 | empty-lines: 18 | max: 3 19 | level: error 20 | hyphens: 21 | level: error 22 | truthy: disable 23 | comments: disable 24 | comments-indentation: disable 25 | indentation: disable 26 | key-duplicates: enable 27 | line-length: 28 | max: 150 29 | level: warning 30 | new-lines: 31 | type: unix 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ansible-development-kit 2 | ========= 3 | [![License](https://img.shields.io/badge/license-Apache-green.svg?style=flat)](https://raw.githubusercontent.com/lean-delivery/ansible-development-kit/master/LICENSE) 4 | [![Build Status](https://travis-ci.org/lean-delivery/ansible-development-kit.svg?branch=master)](https://travis-ci.org/lean-delivery/ansible-development-kit) 5 | [![Build Status](https://gitlab.com/lean-delivery/ansible-development-kit/badges/master/build.svg)](https://gitlab.com/lean-delivery/ansible-development-kit/pipelines) 6 | 7 | ## How to use: 8 | 9 | pip install cookiecutter 10 | 11 | ### Create a new role 12 | 13 | - cookiecutter https://github.com/lean-delivery/ansible-development-kit 14 | 15 | or 16 | 17 | - molecule init template --url https://github.com/lean-delivery/ansible-development-kit 18 | 19 | Enter for the role name question a value without the ansible-role- prefix, e.g. example. 20 | 21 | Make changes in the corresponding files: copyright section in LICENSE, badge section in README.md 22 | (you can get galaxy's role id by running: `ansible-galaxy info lean_delivery.example |grep '\bid'`), etc. 23 | 24 | ### Update an existing role 25 | 26 | 1. cd ansible-role-example 27 | 2. cookiecutter https://github.com/lean-delivery/ansible-development-kit --output-dir .. --overwrite-if-exists 28 | 3. git status 29 | 4. git add . -p 30 | 31 | ``` 32 | Useful commands: 33 | - y - add this hunk to commit 34 | - n - do not add this hunk to commit 35 | - d - do not add this hunk or any of the later hunks in this file 36 | - s - split the current hunk into smaller hunks 37 | - e - manually edit the hunk 38 | ``` 39 | 40 | 5. git commit -m "Updated by cookiecutter and ansible-development-kit" 41 | 42 | In order not to provide the same answers for cookecutter's questions it makes sense to put in the role's directory a config file `.cookiecutter.yml` like this: 43 | 44 | ```yaml 45 | --- 46 | default_context: 47 | role_name: example 48 | ``` 49 | 50 | To switch betweens Linux and Windows molecule tests add this variables to `.cookiecutter.yml`: 51 | ```yaml 52 | --- 53 | default_context: 54 | role_name: example 55 | linux_tests: "true" 56 | windows_tests: "false" 57 | ``` 58 | 59 | To increase root volume size for Linux and Windows platforms in AWS add this variables to `.cookiecutter.yml`: 60 | ```yaml 61 | --- 62 | default_context: 63 | role_name: example 64 | customize_vol_size_linux: "true" 65 | volume_size_linux: 10 66 | customize_vol_size_windows: "true" 67 | volume_size_windows: 32 68 | ``` 69 | 70 | and run cookiecutter the following way: 71 | 72 | cookiecutter https://github.com/lean-delivery/ansible-development-kit --output-dir .. --overwrite-if-exists --config-file .cookiecutter.yml --no-input 73 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.ansible-lint: -------------------------------------------------------------------------------- 1 | exclude_paths: 2 | - ./.travis.yml 3 | - ./molecule/ 4 | rulesdir: 5 | - ~/ansible-lint-rules/rules/ 6 | use_default_rules: true 7 | verbosity: 1 -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.cookiecutter.yml: -------------------------------------------------------------------------------- 1 | --- 2 | default_context: 3 | role_name: {{ cookiecutter.role_name }} 4 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | 13 | 14 | ##### SUMMARY 15 | 16 | 17 | ##### ISSUE TYPE 18 | - Bug Report 19 | 20 | ##### COMPONENT NAME 21 | 23 | 24 | ##### ANSIBLE VERSION 25 | 26 | ``` 27 | 28 | ``` 29 | 30 | ##### CONFIGURATION 31 | 34 | 35 | ##### OS / ENVIRONMENT 36 | 40 | 41 | ##### STEPS TO REPRODUCE 42 | 44 | 45 | 46 | ```yaml 47 | 48 | ``` 49 | 50 | 51 | 52 | ##### EXPECTED RESULTS 53 | 54 | 55 | ##### ACTUAL RESULTS 56 | 57 | 58 | 59 | ``` 60 | 61 | ``` 62 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.github/ISSUE_TEMPLATE/documentation_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 📝 Documentation Report 3 | about: Ask us about docs 4 | 5 | --- 6 | 7 | 13 | 14 | ##### SUMMARY 15 | 16 | 17 | ##### ISSUE TYPE 18 | - Documentation Report 19 | 20 | ##### COMPONENT NAME 21 | 23 | 24 | ##### ANSIBLE VERSION 25 | 26 | ``` 27 | 28 | ``` 29 | 30 | ##### CONFIGURATION 31 | 34 | 35 | ##### OS / ENVIRONMENT 36 | 40 | 41 | ##### STEPS TO REPRODUCE 42 | 44 | 45 | 46 | ```yaml 47 | 48 | ``` 49 | 50 | 51 | 52 | ##### EXPECTED RESULTS 53 | 54 | 55 | ##### ACTUAL RESULTS 56 | 57 | 58 | 59 | ``` 60 | 61 | ``` 62 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ✨ Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | 13 | 14 | ##### SUMMARY 15 | 16 | 17 | ##### ISSUE TYPE 18 | - Feature Idea 19 | 20 | ##### COMPONENT NAME 21 | 23 | 24 | ##### ANSIBLE VERSION 25 | 26 | ``` 27 | 28 | ``` 29 | 30 | ##### CONFIGURATION 31 | 34 | 35 | ##### OS / ENVIRONMENT 36 | 40 | 41 | ##### STEPS TO REPRODUCE 42 | 44 | 45 | 46 | ```yaml 47 | 48 | ``` 49 | 50 | 51 | 52 | ##### EXPECTED RESULTS 53 | 54 | 55 | ##### ACTUAL RESULTS 56 | 57 | 58 | 59 | ``` 60 | 61 | ``` 62 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Pull Request Template 2 | 3 | ## Description 4 | 5 | Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. 6 | 7 | Fixes # (issue) 8 | 9 | ## Type of change 10 | 11 | Please delete options that are not relevant. 12 | 13 | - [ ] Bug fix (non-breaking change which fixes an issue) 14 | - [ ] New feature (non-breaking change which adds functionality) 15 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 16 | - [ ] This change requires a documentation update 17 | 18 | ## Reviews 19 | 20 | Please identify developer to review this change 21 | 22 | - [ ] @developer 23 | 24 | ## Checklist: 25 | 26 | - [ ] I have performed a self-review of my own code 27 | - [ ] I have made corresponding changes to the documentation 28 | - [ ] My changes generate no new warnings 29 | - [ ] I have added tests that prove my fix is effective or that my feature works 30 | - [ ] New and existing tests pass with my changes 31 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.pyc 3 | *.rst 4 | *.log -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Run all tests 3 | default: 4 | image: 5 | name: leandelivery/docker-ansible-ci:ansible-{{ cookiecutter.min_ansible_version }} 6 | 7 | stages: 8 | - lint 9 | - deployment test 10 | 11 | before_script: 12 | - rm -rf molecule/resources/provisioning 13 | - ansible --version 14 | - ansible-lint --version 15 | - molecule --version 16 | - git clone https://github.com/lean-delivery/ansible-molecule-drivers.git molecule/resources/provisioning 17 | 18 | variables: 19 | GET_SOURCES_ATTEMPTS: "5" 20 | 21 | Lint: 22 | stage: lint 23 | before_script: 24 | - git clone https://github.com/lean-delivery/ansible-lint-rules.git ~/ansible-lint-rules 25 | script: 26 | - yamllint . -c .yamllint 27 | - ansible-lint . -c .ansible-lint 28 | after_script: 29 | - rm -rf ~/ansible-lint-rules 30 | tags: 31 | - aws 32 | 33 | Docker {{ cookiecutter.role_name }}: 34 | stage: deployment test 35 | script: 36 | - molecule test -s default 37 | tags: 38 | - aws 39 | 40 | AWS {{ cookiecutter.role_name }}: 41 | variables: 42 | AWS_REGION: {{ cookiecutter.aws_region }} 43 | stage: deployment test 44 | script: 45 | - molecule test -s cloud-aws-direct 46 | tags: 47 | - aws 48 | 49 | AZURE {{ cookiecutter.role_name }}: 50 | stage: deployment test 51 | script: 52 | - molecule test -s cloud-azure-direct 53 | tags: 54 | - azure 55 | 56 | .EPC {{ cookiecutter.role_name }}: 57 | variables: 58 | EPC_REGION: {{ cookiecutter.epc_region }} 59 | stage: deployment test 60 | script: 61 | - molecule test -s cloud-epc-delegated 62 | tags: 63 | - delegated 64 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dist: bionic 3 | sudo: required 4 | 5 | language: python 6 | python: 7 | - "3.7" 8 | 9 | services: 10 | - docker 11 | 12 | before_install: 13 | - git clone https://github.com/lean-delivery/ansible-lint-rules.git ~/ansible-lint-rules 14 | 15 | install: 16 | - pip3 install --upgrade ansible==2.8.* docker 17 | - pip3 install molecule==2.22 18 | - pip3 install git+https://github.com/ansible/ansible-lint.git 19 | - ansible --version 20 | - ansible-lint --version 21 | 22 | script: 23 | - yamllint . -c .yamllint 24 | - ansible-lint . -c .ansible-lint 25 | - molecule test -s default 26 | 27 | notifications: 28 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 29 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | braces: 6 | max-spaces-inside: 1 7 | level: error 8 | brackets: 9 | max-spaces-inside: 1 10 | level: error 11 | colons: 12 | max-spaces-after: -1 13 | level: error 14 | commas: 15 | max-spaces-after: -1 16 | level: error 17 | empty-lines: 18 | max: 3 19 | level: error 20 | hyphens: 21 | level: error 22 | truthy: disable 23 | comments: disable 24 | comments-indentation: disable 25 | indentation: disable 26 | key-duplicates: enable 27 | line-length: 28 | max: 150 29 | level: warning 30 | new-lines: 31 | type: unix 32 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/LICENSE: -------------------------------------------------------------------------------- 1 | {%- if cookiecutter.license == "Apache" -%} 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright {{ cookiecutter.copyright_year }} {{ cookiecutter.copyright_owner }} 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | 204 | {%- elif cookiecutter.license == "MIT" -%} 205 | # MIT license content here 206 | 207 | {%- elif cookiecutter.license == "BSD-3" -%} 208 | # BSD-3 possible license content here 209 | 210 | {%- elif cookiecutter.license == "GPLv3" -%} 211 | # GPLv3 possible license content here 212 | {%- endif %} -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/README.md: -------------------------------------------------------------------------------- 1 | {{ cookiecutter.role_name }} role 2 | ========= 3 | [![License](https://img.shields.io/badge/license-Apache-green.svg?style=flat)](https://raw.githubusercontent.com/lean-delivery/ansible-role-{{ cookiecutter.role_name }}/master/LICENSE) 4 | [![Build Status](https://travis-ci.org/lean-delivery/ansible-role-{{ cookiecutter.role_name }}.svg?branch=master)](https://travis-ci.org/lean-delivery/ansible-role-{{ cookiecutter.role_name }}) 5 | [![Build Status](https://gitlab.com/lean-delivery/ansible-role-{{ cookiecutter.role_name }}/badges/master/pipeline.svg)](https://gitlab.com/lean-delivery/ansible-role-{{ cookiecutter.role_name }}/pipelines) 6 | [![Galaxy](https://img.shields.io/badge/galaxy-lean__delivery.{{ cookiecutter.role_name }}-blue.svg)](https://galaxy.ansible.com/lean_delivery/{{ cookiecutter.role_name }}) 7 | ![Ansible](https://img.shields.io/ansible/role/d/role_id.svg) 8 | ![Ansible](https://img.shields.io/badge/dynamic/json.svg?label=min_ansible_version&url=https%3A%2F%2Fgalaxy.ansible.com%2Fapi%2Fv1%2Froles%2Frole_id%2F&query=$.min_ansible_version) 9 | 10 | A brief description of the role goes here. 11 | 12 | Requirements 13 | ------------ 14 | 15 | Any pre-requisites that may not be covered by Ansible itself or the role should 16 | be mentioned here. For instance, if the role uses the EC2 module, it may be a 17 | good idea to mention in this section that the boto package is required. 18 | 19 | Role Variables 20 | -------------- 21 | 22 | A description of the settable variables for this role should go here, including 23 | any variables that are in defaults/main.yml, vars/main.yml, and any variables 24 | that can/should be set via parameters to the role. Any variables that are read 25 | from other roles and/or the global scope (ie. hostvars, group vars, etc.) should 26 | be mentioned here as well. 27 | 28 | Dependencies 29 | ------------ 30 | 31 | A list of other roles hosted on Galaxy should go here, plus any details in 32 | regards to parameters that may need to be set for other roles, or variables that 33 | are used from other roles. 34 | 35 | Example Playbook 36 | ---------------- 37 | 38 | Including an example of how to use your role (for instance, with variables 39 | passed in as parameters) is always nice for users too: 40 | 41 | - hosts: servers 42 | roles: 43 | - { role: {{ cookiecutter.role_name }}, x: 42 } 44 | 45 | License 46 | ------- 47 | {{ cookiecutter.license }} 48 | 49 | Author Information 50 | ------------------ 51 | 52 | authors: 53 | - {{ cookiecutter.author_name }} 54 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for {{ cookiecutter.role_name }} 3 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for {{ cookiecutter.role_name }} 3 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | role_name: {{ cookiecutter.role_name | replace('-', '_') }} 4 | author: {{ cookiecutter.author_name }} 5 | description: {{ cookiecutter.role_description }} 6 | company: {{ cookiecutter.company_name }} 7 | issue_tracker_url: {{ cookiecutter.issue_tracker_url }} 8 | license: {{ cookiecutter.license }} 9 | min_ansible_version: {{ cookiecutter.min_ansible_version }} 10 | platforms: {{ cookiecutter.platforms }} 11 | galaxy_tags: {{ cookiecutter.galaxy_tags }} 12 | dependencies: [] 13 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/cloud-aws-direct/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: {{ cookiecutter.dependency_name }} 4 | options: 5 | role-file: requirements.yml 6 | driver: 7 | name: ec2 8 | lint: 9 | name: {{ cookiecutter.lint_name }} 10 | options: 11 | config-file: .yamllint 12 | platforms: 13 | 14 | {%- if cookiecutter.linux_tests == "true" %} 15 | - name: test-aws-centos8-{{ cookiecutter.role_name }} 16 | image: {{ cookiecutter.image_centos8 }} 17 | platform: centos8 18 | instance_type: {{ cookiecutter.instance_type }} 19 | {% if cookiecutter.customize_vol_size_linux == "true" %} 20 | volume_size: {{ cookiecutter.volume_size_linux }} 21 | {% endif %} 22 | region: {{ cookiecutter.aws_region }} 23 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 24 | assign_public_ip: false 25 | spot_price: {{ cookiecutter.spot_price }} 26 | security_group_name: 27 | - default 28 | wait_timeout: 1800 29 | ssh_user: centos 30 | groups: 31 | - rhel_family 32 | 33 | - name: test-aws-centos7-{{ cookiecutter.role_name }} 34 | image: {{ cookiecutter.image_centos7 }} 35 | platform: centos7 36 | instance_type: {{ cookiecutter.instance_type }} 37 | {% if cookiecutter.customize_vol_size_linux == "true" %} 38 | volume_size: {{ cookiecutter.volume_size_linux }} 39 | {% endif %} 40 | region: {{ cookiecutter.aws_region }} 41 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 42 | assign_public_ip: false 43 | spot_price: {{ cookiecutter.spot_price }} 44 | security_group_name: 45 | - default 46 | wait_timeout: 1800 47 | ssh_user: centos 48 | groups: 49 | - rhel_family 50 | 51 | # - name: test-aws-centos6-{{ cookiecutter.role_name }} 52 | # image: {{ cookiecutter.image_centos6 }} 53 | # platform: centos6 54 | # instance_type: m4.large 55 | #{% if cookiecutter.customize_vol_size_linux == "true" %} 56 | # volume_size: {{ cookiecutter.volume_size_linux }} 57 | #{% endif %} 58 | # region: {{ cookiecutter.aws_region }} 59 | # vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 60 | # assign_public_ip: false 61 | # spot_price: {{ cookiecutter.spot_price }} 62 | # security_group_name: 63 | # - default 64 | # wait_timeout: 1800 65 | # ssh_user: centos 66 | # groups: 67 | # - rhel_family 68 | 69 | - name: test-aws-ubuntu16-{{ cookiecutter.role_name }} 70 | image: {{ cookiecutter.image_ubuntu16 }} 71 | platform: ubuntu16 72 | instance_type: {{ cookiecutter.instance_type }} 73 | {% if cookiecutter.customize_vol_size_linux == "true" %} 74 | volume_size: {{ cookiecutter.volume_size_linux }} 75 | {% endif %} 76 | region: {{ cookiecutter.aws_region }} 77 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 78 | assign_public_ip: false 79 | security_group_name: 80 | - default 81 | spot_price: {{ cookiecutter.spot_price }} 82 | wait_timeout: 1800 83 | ssh_user: ubuntu 84 | groups: 85 | - debian_family 86 | 87 | - name: test-aws-ubuntu18-{{ cookiecutter.role_name }} 88 | image: {{ cookiecutter.image_ubuntu18 }} 89 | platform: ubuntu18 90 | instance_type: {{ cookiecutter.instance_type }} 91 | {% if cookiecutter.customize_vol_size_linux == "true" %} 92 | volume_size: {{ cookiecutter.volume_size_linux }} 93 | {% endif %} 94 | region: {{ cookiecutter.aws_region }} 95 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 96 | assign_public_ip: false 97 | security_group_name: 98 | - default 99 | spot_price: {{ cookiecutter.spot_price }} 100 | wait_timeout: 1800 101 | ssh_user: ubuntu 102 | groups: 103 | - debian_family 104 | 105 | - name: test-aws-Debian9-{{ cookiecutter.role_name }} 106 | image: {{ cookiecutter.image_debian9 }} 107 | platform: debian9 108 | instance_type: {{ cookiecutter.instance_type }} 109 | {% if cookiecutter.customize_vol_size_linux == "true" %} 110 | volume_size: {{ cookiecutter.volume_size_linux }} 111 | {% endif %} 112 | region: {{ cookiecutter.aws_region }} 113 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 114 | assign_public_ip: false 115 | spot_price: {{ cookiecutter.spot_price }} 116 | security_group_name: 117 | - default 118 | wait_timeout: 1800 119 | ssh_user: admin 120 | groups: 121 | - debian_family 122 | 123 | - name: test-aws-Amazon-{{ cookiecutter.role_name }} 124 | image: {{ cookiecutter.image_amazon }} 125 | platform: amazon 126 | instance_type: {{ cookiecutter.instance_type }} 127 | {% if cookiecutter.customize_vol_size_linux == "true" %} 128 | volume_size: {{ cookiecutter.volume_size_linux }} 129 | {% endif %} 130 | region: {{ cookiecutter.aws_region }} 131 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 132 | assign_public_ip: false 133 | spot_price: {{ cookiecutter.spot_price }} 134 | security_group_name: 135 | - default 136 | wait_timeout: 1800 137 | ssh_user: ec2-user 138 | groups: 139 | - rhel_family 140 | 141 | - name: test-aws-Amazon2-{{ cookiecutter.role_name }} 142 | image: {{ cookiecutter.image_amazon2 }} 143 | platform: amazon2 144 | instance_type: {{ cookiecutter.instance_type }} 145 | {% if cookiecutter.customize_vol_size_linux == "true" %} 146 | volume_size: {{ cookiecutter.volume_size_linux }} 147 | {% endif %} 148 | region: {{ cookiecutter.aws_region }} 149 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 150 | assign_public_ip: false 151 | spot_price: {{ cookiecutter.spot_price }} 152 | security_group_name: 153 | - default 154 | wait_timeout: 1800 155 | ssh_user: ec2-user 156 | groups: 157 | - rhel_family 158 | {% endif -%} 159 | 160 | {%- if cookiecutter.windows_tests == "true" %} 161 | - name: test-aws-Windows2016-{{ cookiecutter.role_name }} 162 | image_id: {{ cookiecutter.image_windows2016 }} 163 | platform: windows2016core 164 | region: {{ cookiecutter.aws_region }} 165 | instance_type: {{ cookiecutter.instance_type }} 166 | {% if cookiecutter.customize_vol_size_windows == "true" %} 167 | volume_size: {{ cookiecutter.volume_size_windows }} 168 | {% endif %} 169 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 170 | assign_public_ip: false 171 | spot_price: 0.14 172 | security_group_name: 173 | - default 174 | wait_timeout: 1800 175 | groups: 176 | - windows 177 | 178 | - name: test-aws-Windows2019-{{ cookiecutter.role_name }} 179 | image_id: {{ cookiecutter.image_windows2019 }} 180 | platform: windows2019core 181 | region: {{ cookiecutter.aws_region }} 182 | instance_type: {{ cookiecutter.instance_type }} 183 | {% if cookiecutter.customize_vol_size_windows == "true" %} 184 | volume_size: {{ cookiecutter.volume_size_windows }} 185 | {% endif %} 186 | vpc_subnet_id: {{ cookiecutter.vpc_subnet_id }} 187 | assign_public_ip: false 188 | spot_price: 0.14 189 | security_group_name: 190 | - default 191 | wait_timeout: 1800 192 | groups: 193 | - windows 194 | {% endif -%} 195 | 196 | {% raw -%} 197 | provisioner: 198 | name: ansible 199 | log: true 200 | config_options: 201 | defaults: 202 | callback_whitelist: profile_tasks,timer 203 | inventory: 204 | group_vars: 205 | windows: 206 | ansible_connection: winrm 207 | ansible_password: "{{ lookup('env', 'WINRM_ADMIN_PWD') | default('M0leCule123!', true) }}" 208 | ansible_winrm_transport: credssp 209 | ansible_winrm_server_cert_validation: ignore 210 | {%- endraw %} 211 | playbooks: 212 | create: ../resources/provisioning/AWS/create.yml 213 | prepare: ../resources/provisioning/AWS/prepare.yml 214 | destroy: ../resources/provisioning/AWS/destroy.yml 215 | verify: ../resources/tests/verify.yml 216 | lint: 217 | name: {{ cookiecutter.provisioner_lint_name }} 218 | scenario: 219 | name: cloud-aws-direct 220 | verifier: 221 | name: {{ cookiecutter.verifier_name }} 222 | lint: 223 | name: {{ cookiecutter.verifier_lint_name }} 224 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/cloud-aws-direct/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | roles: 5 | - role: ansible-role-{{ cookiecutter.role_name }} 6 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/cloud-azure-direct/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: {{ cookiecutter.dependency_name }} 4 | options: 5 | role-file: requirements.yml 6 | driver: 7 | name: azure 8 | lint: 9 | name: {{ cookiecutter.lint_name }} 10 | options: 11 | config-file: .yamllint 12 | platforms: 13 | 14 | {%- if cookiecutter.linux_tests == "true" %} 15 | - name: test-azure-centos7-{{ cookiecutter.role_name }} 16 | platform: centos7 17 | assign_public_ip: true 18 | vm_size: {{ cookiecutter.az_vm_size }} 19 | az_location: {{ cookiecutter.az_location }} 20 | az_resource_group_name: {{ cookiecutter.az_resource_group_name }} 21 | az_virtual_network_name: {{ cookiecutter.az_virtual_network_name }} 22 | az_subnet_name: {{ cookiecutter.az_subnet_name }} 23 | az_network_security_group: {{ cookiecutter.az_network_security_group }} 24 | groups: 25 | - rhel_family 26 | 27 | - name: test-azure-centos6-{{ cookiecutter.role_name }} 28 | platform: centos6 29 | assign_public_ip: false 30 | vm_size: {{ cookiecutter.az_vm_size }} 31 | az_location: {{ cookiecutter.az_location }} 32 | az_resource_group_name: {{ cookiecutter.az_resource_group_name }} 33 | az_virtual_network_name: {{ cookiecutter.az_virtual_network_name }} 34 | az_subnet_name: {{ cookiecutter.az_subnet_name }} 35 | az_network_security_group: {{ cookiecutter.az_network_security_group }} 36 | groups: 37 | - rhel_family 38 | 39 | - name: test-azure-ubuntu16-{{ cookiecutter.role_name }} 40 | platform: ubuntu16 41 | assign_public_ip: false 42 | vm_size: {{ cookiecutter.az_vm_size }} 43 | az_location: {{ cookiecutter.az_location }} 44 | az_resource_group_name: {{ cookiecutter.az_resource_group_name }} 45 | az_virtual_network_name: {{ cookiecutter.az_virtual_network_name }} 46 | az_subnet_name: {{ cookiecutter.az_subnet_name }} 47 | az_network_security_group: {{ cookiecutter.az_network_security_group }} 48 | groups: 49 | - debian_family 50 | 51 | - name: test-azure-ubuntu18-{{ cookiecutter.role_name }} 52 | platform: ubuntu18 53 | assign_public_ip: false 54 | vm_size: {{ cookiecutter.az_vm_size }} 55 | az_location: {{ cookiecutter.az_location }} 56 | az_resource_group_name: {{ cookiecutter.az_resource_group_name }} 57 | az_virtual_network_name: {{ cookiecutter.az_virtual_network_name }} 58 | az_subnet_name: {{ cookiecutter.az_subnet_name }} 59 | az_network_security_group: {{ cookiecutter.az_network_security_group }} 60 | groups: 61 | - debian_family 62 | 63 | - name: test-azure-Debian9-{{ cookiecutter.role_name }} 64 | platform: debian9 65 | assign_public_ip: false 66 | vm_size: {{ cookiecutter.az_vm_size }} 67 | az_location: {{ cookiecutter.az_location }} 68 | az_resource_group_name: {{ cookiecutter.az_resource_group_name }} 69 | az_virtual_network_name: {{ cookiecutter.az_virtual_network_name }} 70 | az_subnet_name: {{ cookiecutter.az_subnet_name }} 71 | az_network_security_group: {{ cookiecutter.az_network_security_group }} 72 | groups: 73 | - debian_family 74 | {% endif -%} 75 | 76 | {%- if cookiecutter.windows_tests == "true" %} 77 | - name: test-azure-Windows2016-{{ cookiecutter.role_name }} 78 | platform: windows2016core 79 | assign_public_ip: false 80 | vm_size: {{ cookiecutter.az_vm_size }} 81 | az_location: {{ cookiecutter.az_location }} 82 | az_resource_group_name: {{ cookiecutter.az_resource_group_name }} 83 | az_virtual_network_name: {{ cookiecutter.az_virtual_network_name }} 84 | az_subnet_name: {{ cookiecutter.az_subnet_name }} 85 | az_network_security_group: {{ cookiecutter.az_network_security_group }} 86 | groups: 87 | - windows 88 | 89 | - name: test-azure-Windows2019-{{ cookiecutter.role_name }} 90 | platform: windows2019core 91 | assign_public_ip: true 92 | vm_size: {{ cookiecutter.az_vm_size }} 93 | az_location: {{ cookiecutter.az_location }} 94 | az_resource_group_name: {{ cookiecutter.az_resource_group_name }} 95 | az_virtual_network_name: {{ cookiecutter.az_virtual_network_name }} 96 | az_subnet_name: {{ cookiecutter.az_subnet_name }} 97 | az_network_security_group: {{ cookiecutter.az_network_security_group }} 98 | groups: 99 | - windows 100 | {% endif -%} 101 | 102 | {% raw -%} 103 | provisioner: 104 | name: ansible 105 | log: true 106 | config_options: 107 | defaults: 108 | callback_whitelist: profile_tasks,timer 109 | inventory: 110 | group_vars: 111 | windows: 112 | ansible_connection: winrm 113 | ansible_password: "{{ lookup('env', 'WINRM_ADMIN_PWD') | default('M0leCule123!', true) }}" 114 | ansible_winrm_transport: credssp 115 | ansible_winrm_server_cert_validation: ignore 116 | {%- endraw %} 117 | playbooks: 118 | create: ../resources/provisioning/AZURE/create.yml 119 | prepare: ../resources/provisioning/AZURE/prepare.yml 120 | destroy: ../resources/provisioning/AZURE/destroy.yml 121 | verify: ../resources/tests/verify.yml 122 | lint: 123 | name: {{ cookiecutter.provisioner_lint_name }} 124 | scenario: 125 | name: cloud-azure-direct 126 | verifier: 127 | name: {{ cookiecutter.verifier_name }} 128 | lint: 129 | name: {{ cookiecutter.verifier_lint_name }} 130 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/cloud-azure-direct/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | roles: 5 | - role: ansible-role-{{ cookiecutter.role_name }} 6 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/cloud-epc-delegated/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: {{ cookiecutter.dependency_name }} 4 | options: 5 | role-file: requirements.yml 6 | driver: 7 | name: delegated 8 | lint: 9 | name: {{ cookiecutter.lint_name }} 10 | options: 11 | config-file: .yamllint 12 | platforms: 13 | - name: test-epc-centos7-{{ cookiecutter.role_name }} 14 | image: CentOS7_64-bit 15 | shape: small 16 | region: {{ cookiecutter.epc_region }} 17 | wait_timeout: 3600 18 | groups: 19 | - rhel_family 20 | - name: test-epc-ubuntu1804-{{ cookiecutter.role_name }} 21 | image: Ubuntu18.04_64-bit 22 | shape: small 23 | region: {{ cookiecutter.epc_region }} 24 | wait_timeout: 3600 25 | groups: 26 | - debian_family 27 | provisioner: 28 | name: ansible 29 | log: true 30 | playbooks: 31 | create: ../resources/provisioning/EPC/create.yml 32 | prepare: ../resources/provisioning/EPC/prepare.yml 33 | destroy: ../resources/provisioning/EPC/destroy.yml 34 | verify: ../resources/tests/verify.yml 35 | config_options: 36 | ssh_connection: 37 | control_path: "/var/ans/%%h" 38 | lint: 39 | name: {{ cookiecutter.provisioner_lint_name }} 40 | env: 41 | ANSIBLE_LIBRARY: ${ANSIBLE_LIBRARY} 42 | scenario: 43 | name: cloud-epc-delegated 44 | verifier: 45 | name: {{ cookiecutter.verifier_name }} 46 | options: 47 | verbose: true 48 | directory: ../resources/tests/ 49 | lint: 50 | name: {{ cookiecutter.verifier_lint_name }} 51 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/cloud-epc-delegated/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | roles: 5 | - role: ansible-role-{{ cookiecutter.role_name }} 6 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/default/Dockerfile.j2: -------------------------------------------------------------------------------- 1 | # Molecule managed 2 | 3 | {% raw -%} 4 | {% if item.registry is defined %} 5 | FROM {{ item.registry.url }}/{{ item.image }} 6 | {% else %} 7 | FROM {{ item.image }} 8 | {% endif %} 9 | 10 | RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ 11 | elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python2-dnf bash && dnf clean all; \ 12 | elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash util-linux && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ 13 | elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ 14 | elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ 15 | elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi 16 | 17 | RUN if [ -f /sbin/agetty ]; then cp /bin/true /sbin/agetty; \ 18 | elif [ -f /sbin/mingetty ]; then cp /bin/true /sbin/mingetty; fi 19 | {%- endraw %} 20 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: {{ cookiecutter.dependency_name }} 4 | options: 5 | role-file: requirements.yml 6 | driver: 7 | name: docker 8 | lint: 9 | name: {{ cookiecutter.lint_name }} 10 | options: 11 | config-file: .yamllint 12 | platforms: 13 | - name: test-docker-centos7-{{ cookiecutter.role_name }} 14 | image: leandelivery/docker-systemd:centos7 15 | privileged: {{ cookiecutter.docker_privileged }} 16 | groups: 17 | - rhel_family 18 | - name: test-docker-ubuntu1804-{{ cookiecutter.role_name }} 19 | image: leandelivery/docker-systemd:ubuntu-18.04 20 | privileged: {{ cookiecutter.docker_privileged }} 21 | security_opts: 22 | - seccomp=unconfined 23 | volumes: 24 | - /sys/fs/cgroup:/sys/fs/cgroup:ro 25 | tmpfs: 26 | - /tmp 27 | - /run 28 | capabilities: 29 | - SYS_ADMIN 30 | groups: 31 | - debian_family 32 | provisioner: 33 | name: ansible 34 | log: true 35 | lint: 36 | name: {{ cookiecutter.provisioner_lint_name }} 37 | config_options: 38 | defaults: 39 | callback_whitelist: profile_tasks,timer 40 | playbooks: 41 | verify: ../resources/tests/verify.yml 42 | scenario: 43 | name: default 44 | verifier: 45 | name: {{ cookiecutter.verifier_name }} 46 | lint: 47 | name: {{ cookiecutter.verifier_lint_name }} 48 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/default/playbook.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | roles: 5 | - role: ansible-role-{{ cookiecutter.role_name }} 6 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/molecule/resources/tests/verify.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This is an example playbook to execute Ansible tests. 3 | 4 | - name: Verify 5 | hosts: all 6 | tasks: 7 | - name: Example assertion 8 | assert: 9 | that: true 10 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | [] 3 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for {{ cookiecutter.role_name }} 3 | -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/templates/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lean-delivery/ansible-development-kit/4476330356aad88e98b2072089d1fccaff525c6c/ansible-role-{{cookiecutter.role_name}}/templates/.gitkeep -------------------------------------------------------------------------------- /ansible-role-{{cookiecutter.role_name}}/vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for {{ cookiecutter.role_name }} 3 | -------------------------------------------------------------------------------- /cookiecutter.json: -------------------------------------------------------------------------------- 1 | { 2 | "role_name": "default_role", 3 | "license" : ["Apache", "MIT", "BSD-3", "GPLv3"], 4 | "author_name" : "Lean Delivery Team ", 5 | "docker_privileged": "true", 6 | "dependency_name": "galaxy", 7 | "lint_name": "yamllint", 8 | "provisioner_name": "ansible", 9 | "provisioner_lint_name": "ansible-lint", 10 | "verifier_name": "ansible", 11 | "verifier_lint_name": "ansible-lint", 12 | "min_ansible_version": "2.8", 13 | "company_name": "EPAM Systems", 14 | "role_description": "Yet Another Ansible Role From Lean Delivery", 15 | "issue_tracker_url": "https://github.com/lean-delivery/ansible-role-{{ cookiecutter.role_name }}/issues", 16 | "galaxy_tags": "[development, system]", 17 | "platforms":"[{name: [EL], versions: [7]}]", 18 | "vpc_subnet_id": "subnet-0f2b9cd66faea38af", 19 | "aws_region": "us-east-1", 20 | "epc_region": "EPAM-BY2", 21 | "copyright_year": "2019", 22 | "copyright_owner": "EPAM Systems", 23 | "image_centos8": "ami-0ed2ad9dc845b42b6", 24 | "image_centos7": "ami-9887c6e7", 25 | "image_centos6": "ami-1585c46a", 26 | "image_ubuntu16": "ami-09677e0a6b14905b0", 27 | "image_ubuntu18": "ami-012fd5eb46f56731f", 28 | "image_debian9": "ami-003f19e0e687de1cd", 29 | "image_debian8": "ami-b14ba7a7", 30 | "image_amazon": "ami-035b3c7efe6d061d5", 31 | "image_amazon2": "ami-0b898040803850657", 32 | "image_windows2016": "ami-00a20f508263efd30", 33 | "image_windows2019": "ami-0477b9335a5a75438", 34 | "instance_type": "m5.large", 35 | "customize_vol_size_linux": "false", 36 | "volume_size_linux": 8, 37 | "customize_vol_size_windows": "false", 38 | "volume_size_windows": 30, 39 | "spot_price": "0.04", 40 | "linux_tests": "true", 41 | "windows_tests": "true", 42 | "az_location": "northeurope", 43 | "az_resource_group_name": "epm-ldi", 44 | "az_virtual_network_name": "epm-ldi-northeurope-vnet", 45 | "az_subnet_name": "epm-ldi-northeurope-subnet", 46 | "az_network_security_group": "epm-ldi-northeurope-sg", 47 | "az_vm_size": "Standard_D2s_v3" 48 | } 49 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | title: Ansible Development Kit 2 | remote_theme: pmarsceill/just-the-docs 3 | search_enabled: true 4 | highlighter: rouge 5 | markdown: kramdown 6 | kramdown: 7 | toc_levels: 1..2 8 | -------------------------------------------------------------------------------- /docs/ansible_code_snippets/ansible_code_snippets.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Ansible Code Snippets 4 | nav_order: 3 5 | has_children: false 6 | permalink: /docs/ansible_code_snippets 7 | --- 8 | 9 | # Ansible Code Snippets 10 | {: .no_toc } 11 | 12 | This document demonstrates useful code snippets for Ansible roles/playbooks. These snippets are provided for Ansible role authors and contributors to avoid repetitive typing for typical tasks and steps. 13 | 14 | ## Table of contents 15 | {: .no_toc .text-delta } 16 | 17 | * TOC 18 | {:toc} 19 | 20 | --- 21 | 22 | ## Tasks and Variables Separation 23 | 24 | When working with multiple OS versions/distributions (RedHat vs Debian for instance), there are packages, configuration files and parameters that are vastly different than one another. There can even be instances in which sub-versions of OSes can have major differences, such as service vs. systemctl in CentOS 6 vs. 7 etc. 25 | 26 | There are different ways to handle these issues both in the same playbook or play or by separating out tasks to other task files. 27 | 28 | ### Variables Separation 29 | 30 | ```yaml {% raw %} 31 | # bad 32 | - name: Set path 33 | set_fact: 34 | my_var: /tmp/mypath 35 | when: ansible_distribution == 'CentOS' 36 | 37 | # good 38 | - name: Load a variable file based on the OS type, or a default if not found 39 | include_vars: '{{ platform_vars }}' 40 | with_first_found: 41 | - '{{ ansible_os_family }}.yml' 42 | - '{{ ansible_distribution }}.yml' 43 | - default.yml 44 | loop_control: 45 | loop_var: platform_vars 46 | 47 | - name: Load a variable file based on the service manager 48 | include_vars: '{{ service_manager }}' 49 | with_first_found: 50 | - '{{ ansible_service_mgr }}.yml' 51 | - systemv.yml 52 | loop_control: 53 | loop_var: service_manager {% endraw %} 54 | ``` 55 | 56 | ### Tasks Separation 57 | 58 | ```yaml {% raw %} 59 | # bad 60 | - name: ensure that directory for apache is ready 61 | file: 62 | path: '{{ apache_dir }}' 63 | owner: '{{ web_server_user }}' 64 | group: '{{ web_server_group }}' 65 | recurse: true 66 | state: directory 67 | become: true 68 | when: ansible_os_family == 'RedHat' 69 | 70 | # good 71 | - name: Configure and install packages for current OS 72 | include_tasks: '{{ platform_tasks }}' 73 | with_first_found: 74 | - '{{ ansible_os_family }}.yml' 75 | - not_supported.yml 76 | loop_control: 77 | loop_var: platform_tasks {% endraw %} 78 | ``` 79 | 80 | ### Why? 81 | {: .no_toc } 82 | 83 | The way of tasks and variables separation using dynamic includes is more flexible and it's easier to support. For example, to add new OS support you just need to put an additional file into Ansible role with corresponding name and content without changing the exact code of Ansible role or playbook. Thus avoid separation of code and variables by using `when` conditionals in playbooks. 84 | 85 | --- 86 | 87 | ## Install requirements 88 | 89 | ```yaml {% raw %} 90 | - name: Install requirements 91 | package: 92 | name: '{{ requirements }}' 93 | state: present 94 | register: installed_packages 95 | until: installed_packages is succeeded 96 | become: true 97 | 98 | - name: Install required packages 99 | package: 100 | name: '{{ packages_base | union(packages_additional) | unique }}' 101 | state: present 102 | register: installed_packages 103 | until: installed_packages is succeeded 104 | become: true {% endraw %} 105 | ``` 106 | 107 | --- 108 | 109 | ## Selinux support 110 | 111 | ```yaml {% raw %} 112 | --- 113 | - name: install ansible selinux support library 114 | become: true 115 | package: 116 | name: libselinux-python 117 | state: present 118 | register: installed_package 119 | until: installed_package is succeeded 120 | 121 | - name: Install ansible selinux configure libraries 122 | become: true 123 | package: 124 | name: 125 | - policycoreutils-python 126 | - libsemanage-python 127 | state: present 128 | register: installed_package 129 | until: installed_package is succeeded 130 | when: ansible_selinux.status == "enabled" 131 | 132 | - name: Enable connections to HTTP port 133 | become: true 134 | seport: 135 | ports: "{{ selinux_ports }}" 136 | proto: tcp 137 | setype: http_port_t 138 | state: present 139 | when: 140 | - ansible_selinux.status == "enabled" 141 | - ansible_selinux.mode != "disabled" {% endraw %} 142 | ``` 143 | 144 | --- 145 | 146 | ## Conditionals 147 | 148 | ### Avoid comparison to empty string and 'true/false' 149 | 150 | Use `when: var` rather than `when: var == True` (or conversely `when: not var`) 151 | Use `when: var` rather than `when: var != ""` (or conversely `when: not var` rather than `when: var == ""`) 152 | 153 | 154 | ### Why? 155 | {: .no_toc } 156 | 157 | Ansible came from Python world. It's supposed to follow `Zen of Python` principles and related codestyle conventions. As for conditionals, Python code guides recommend to use direct truth value testing. 158 | 159 | -------------------------------------------------------------------------------- /docs/ansible_style_guide/ansible_style_guide.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Ansible Styleguide 4 | nav_order: 3 5 | has_children: false 6 | permalink: /docs/ansible_style_guide 7 | --- 8 | 9 | # Ansible Style Guide 10 | {: .no_toc } 11 | 12 | This document defines code guidelines for Ansible roles included in lean-delivery project. These guidelines are provided for Ansible role authors and contributors to ensure that the code of Ansible roles included in the project is following the agreed conventions. Following these conventions makes code better in terms of readability and simplifies further support and development. 13 | 14 | ## Table of contents 15 | {: .no_toc .text-delta } 16 | 17 | * TOC 18 | {:toc} 19 | 20 | --- 21 | 22 | ## Practices 23 | 24 | You should follow the [Best Practices](https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html) defined by the Ansible documentation when developing playbooks. 25 | 26 | ### Why? 27 | {: .no_toc } 28 | 29 | The Ansible developers have a good understanding of how the playbooks work and where they look for certain files. Following these practices will avoid a lot of problems. 30 | 31 | ### Why Doesn't Your Style Follow Theirs? 32 | 33 | The script examples are inconsistent in style throughout the Ansible documentation; the purpose of this document is to define a consistent style that can be used throughout Ansible scripts to create robust, readable code. 34 | 35 | --- 36 | 37 | ## Start of Files 38 | 39 | All YAML files (regardless of their association with Ansible or not) should begin with `---` to define the document start. 40 | 41 | ### Why? 42 | {: .no_toc } 43 | 44 | It's better processed by linters and parsers. It allows easily indicate start of new yaml objects and documents. 45 | 46 | --- 47 | 48 | ## End of Files 49 | 50 | You should always end your files with a newline. 51 | 52 | ### Why? 53 | {: .no_toc } 54 | 55 | This is common Unix best practice, and avoids any prompt misalignment when printing files in a terminal. 56 | 57 | --- 58 | 59 | ## Quotes 60 | 61 | **You should only quote strings when it is absolutely necessary** or required by YAML, and then use single quotes. 62 | Single quotes are preferrable to double since they are shorter and require less efforts to support, especially for roles supporting Windows. 63 | 64 | ### Double quotes should be used in the following cases: 65 | {: .no_toc } 66 | 67 | 1. When they are nested within single quotes (e.g. Jinja map reference) 68 | 69 | ```yaml {% raw %} 70 | - name: start all services 71 | service: 72 | name: '{{ item["service_name"] }}' 73 | state: started 74 | enabled: true 75 | loop: '{{ services }}' {% endraw %} 76 | ``` 77 | 78 | 2. When your string requires escaping characters (e.g. using "\n" to represent a newline) 79 | 80 | ```yaml 81 | # double quotes to escape characters 82 | - name print text with two lines 83 | debug: 84 | msg: "Line one\nLine two" 85 | ``` 86 | 87 | 3. When you need to split long string without spaces to several lines: 88 | 89 | ```yaml 90 | # long string without spaces 91 | - name Set plugin url 92 | set_fact: 93 | plugin_jar: "https://github.com/checkstyle/\ 94 | sonar-checkstyle/releases/download/4.17/\ 95 | checkstyle-sonar-plugin-4.17.jar" 96 | ``` 97 | 98 | ### Why? 99 | {: .no_toc } 100 | 101 | Even though strings are the default type for YAML, syntax highlighting looks better when explicitly set types. This also helps troubleshoot malformed strings when they should be properly escaped to have the desired effect. 102 | 103 | --- 104 | 105 | ## Long strings 106 | 107 | If you write a long string containing whitespaces, it's preferrable to use the "Literal Block Scalar" style and omit all special quoting. Values can span multiple lines using `|` or `>`. Spanning multiple lines using a "Literal Block Scalar" (`|`) will include the newlines and any trailing spaces. Using a "Folded Block Scalar" (`>`) will fold newlines to spaces; it’s used to make what would otherwise be a very long line easier to read and edit: 108 | 109 | ```yaml {% raw %} 110 | java_folder: >- 111 | {{ (java_major_version|int <= 8) 112 | | ternary(java_package + '1.' + java_major_version|string + '.0_' + java_minor_version|string, 113 | java_package + '-' + java_major_version|string + '.' + java_minor_version|string) }} {% endraw %} 114 | ``` 115 | 116 | If you need to preserve line breaks use the following approach: 117 | 118 | ```yaml {% raw %} 119 | - name: Warn on unsupported platform 120 | fail: 121 | msg: | 122 | This role does not support '{{ ansible_os_family }}' platform. 123 | Please contact support@lean-delivery.com {% endraw %} 124 | ``` 125 | --- 126 | 127 | ## Booleans 128 | 129 | Ansible supports many different ways to specify a boolean value: `True/False`, `true/false`, `yes/no`, `1/0`. We prefer to avoid mixing of various styles and stick to one : `true/false`. 130 | 131 | ```yaml 132 | # bad 133 | - name: start nginx 134 | service: 135 | name: nginx 136 | state: started 137 | enabled: yes 138 | become: yes 139 | 140 | # good 141 | - name: start nginx 142 | service: 143 | name: nginx 144 | state: started 145 | enabled: true 146 | become: true 147 | ``` 148 | 149 | ### Why? 150 | The main reasoning behind this is that Python have same convention for boolean values. 151 | 152 | --- 153 | 154 | ## Colon spacing 155 | 156 | Use only one space after the colon when designating a key value pair 157 | 158 | ```yaml 159 | # bad 160 | - name : start nginx 161 | service: 162 | name : nginx 163 | state : started 164 | enabled : true 165 | become : true 166 | 167 | 168 | # good 169 | - name: start nginx 170 | service: 171 | name: nginx 172 | state: started 173 | enabled: true 174 | become: true 175 | ``` 176 | 177 | ### Why? 178 | 179 | It's easier to edit avoiding extra aligning efforts for colons. 180 | 181 | --- 182 | 183 | ## Key-Value pairs 184 | 185 | Ansible allows two types of YAML syntax: 186 | * legacy key=value style 187 | * structured map style 188 | 189 | **Always use the map syntax,** regardless of how many pairs exist in the map. 190 | 191 | ```yaml 192 | # bad 193 | - name: Create configuration file with parameters 194 | file: path=/etc/sensu/conf.d/checks state=directory mode=0755 owner=sensu group=sensu 195 | become: true 196 | 197 | - name: Copy configuration file 198 | copy: dest=/etc/sensu/conf.d/checks/ src=checks/check-memory.json 199 | become: true 200 | 201 | # good 202 | - name: Create configuration file with parameters 203 | file: 204 | path: /etc/sensu/conf.d/checks 205 | state: directory 206 | group: sensu 207 | mode: 0755 208 | owner: sensu 209 | become: true 210 | 211 | - name: Copy configuration file 212 | copy: 213 | dest: /etc/sensu/conf.d/checks/ 214 | src: checks/check-memory.json 215 | become: true 216 | ``` 217 | 218 | ### Why? 219 | {: .no_toc } 220 | 221 | The legacy key=value syntax is used on the command line for adhoc commands. The use of this style within playbooks and roles is a bad practice making playbooks harder to read and support. 222 | 223 | Structured map style makes code more compact in terms of line length and that makes code more easy to read. Each module parameter is places on its own line making possible to comment parameters independently. YAML syntax highlighting works better for this format allowing key/value detection, constants highlighting etc. 224 | 225 | --- 226 | 227 | ## Variable Names 228 | 229 | Use `snake_case` for variable names: 230 | 231 | ```yaml 232 | # bad 233 | - name: set some facts 234 | set_fact: 235 | myBoolean: true 236 | myint: 20 237 | MY_STRING: test 238 | 239 | # good 240 | - name: set some facts 241 | set_fact: 242 | my_boolean: true 243 | my_int: 20 244 | my_string: test 245 | ``` 246 | 247 | ### Why? 248 | {: .no_toc } 249 | 250 | Ansible uses `snake_case` for module names and parameters so it makes sense to extend this convention to variable names to unify style. 251 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: default 3 | title: Ansible Development Kit 4 | nav_order: 1 5 | --- 6 | 7 | # Ansible Development Kit 8 | {: .no_toc } 9 | 10 | Ansible Development Kit is a collection of tools, libraries, and templates are based on Lean Delivery approach and community best practices for roles and playbooks development. 11 | 12 | ## Why this product? 13 | 14 | Ansible Development Kit defines a common workflow for Ansible roles and playbooks development: 15 | 16 | - This a comprehensive framework for roles and playbooks development. 17 | - You do not need to reinvent a wheel and start deep diving in best practice from scratch. Just take for a minute and use predefined framework and deliver high quality automated solution in hours. 18 | - You can avoid pitfalls one the way of becoming true Ansible developer. Framework is hands-on engineering excellence. 19 | - Ansible Development Kit is Software Development Life Cycle compliance. 20 | - Suitable for delivery open source and private solutions. 21 | - Continuous Integration components are already included using reconfigured templates. Just adopt and get value. 22 | - Broad set of open source tools. It is equal to internal licensed products. 23 | 24 | ## What product provides? 25 | 26 | Ansible Development Kit provides: 27 | 28 | - All stages described in accordance with SDLC stages such as Development and Implementation, Testing and Integration, Release Management, Feedback and Analysis. 29 | - Preconfigured assets for integration with required components ex. Version Control System, Continuous Integration, Testing, Release Management. 30 | - Broad set of tools and services on each stage of life cycle including GitLab, GitHub, Travis CI, GitLab Runners, Molecule, TestInfra, Ansible Galaxy, Docker. 31 | - Integration with popular clouds. Amazon, Azure, Google Cloud Platform, EPAM Cloud. 32 | - Public and private hosting of CI process. 33 | - Template based on Cookiecutter framework which represents independent repository with logical and hierarchical structure, contains configuration and test assets to avoid starting development from scratch. 34 | 35 | ## How to make your own? 36 | {: .no_toc } 37 | To organize your own solution based on Ansible Development Kit you need to perform the following: 38 | 39 | 1. Make new organization on GitHub or use already existing to store your repositories: 40 | [https://github.com/organizations/new](https://github.com/organizations/new) 41 | 2. Setup Ansible Galaxy integration with GitHub: 42 | [https://galaxy.ansible.com/docs/contributing/importing.html](https://galaxy.ansible.com/docs/contributing/importing.html) 43 | 3. Setup Travis CI accordingly: 44 | [https://docs.travis-ci.com/user/tutorial/](https://docs.travis-ci.com/user/tutorial/) 45 | 4. Setup Gitlab CI accordingly: 46 | [https://docs.gitlab.com/ee/ci/ci_cd_for_external_repos/github_integration.html](https://docs.gitlab.com/ee/ci/ci_cd_for_external_repos/github_integration.html) 47 | 5. Setup your Gitlab runners if necessary: 48 | See [related Terraform module](https://github.com/lean-delivery/tf-module-aws-gitlab-runner) or [Gitlab-runner Ansible role](https://github.com/lean-delivery/ansible-role-gitlab-runner) and [related Dockerfile](https://github.com/lean-delivery/docker-ansible-ci). 49 | 6. Organize service accounts for your cloud tests. 50 | 7. Create you Cookiecutter templates: 51 | See [our one](https://github.com/lean-delivery/ansible-development-kit) for example. 52 | 8. Add Lint tests according to documentation: 53 | [Yamllint](https://yamllint.readthedocs.io/en/stable/) 54 | [Ansible Lint](https://docs.ansible.com/ansible-lint/) 55 | 9. Add Molecule and Testinfra tests according to documentation: 56 | [Molecule](https://molecule.readthedocs.io/en/stable/) 57 | [Testinfra](https://testinfra.readthedocs.io/en/latest/) 58 | 10. Start contributing. -------------------------------------------------------------------------------- /hooks/post_gen_project.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lean-delivery/ansible-development-kit/4476330356aad88e98b2072089d1fccaff525c6c/hooks/post_gen_project.py --------------------------------------------------------------------------------