├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── defaults └── main.yml ├── handlers └── main.yml ├── meta └── main.yml ├── requirements.yml ├── tasks ├── debug.yml ├── main.yml └── validation.yml ├── tests ├── Vagrantfile ├── ansible.cfg ├── boxes.yml ├── log │ └── .gitkeep ├── plugins │ └── callback │ │ └── idempotence.py ├── roles │ └── .gitkeep ├── setup.sh ├── tasks │ └── main.yml ├── test.yml ├── test_checkmode.sh ├── test_idempotence.sh ├── travis.sh └── vagrant.sh ├── tox.ini └── vars └── main.yml /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | **/roles/* 3 | 4 | # Created by https://www.gitignore.io 5 | 6 | ### Vagrant ### 7 | .vagrant/ 8 | 9 | ### PyCharm ### 10 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 11 | 12 | *.iml 13 | 14 | ## Directory-based project format: 15 | .idea/ 16 | # if you remove the above rule, at least ignore the following: 17 | 18 | # User-specific stuff: 19 | # .idea/workspace.xml 20 | # .idea/tasks.xml 21 | # .idea/dictionaries 22 | 23 | # Sensitive or high-churn files: 24 | # .idea/dataSources.ids 25 | # .idea/dataSources.xml 26 | # .idea/sqlDataSources.xml 27 | # .idea/dynamic.xml 28 | # .idea/uiDesigner.xml 29 | 30 | # Gradle: 31 | # .idea/gradle.xml 32 | # .idea/libraries 33 | 34 | # Mongo Explorer plugin: 35 | # .idea/mongoSettings.xml 36 | 37 | ## File-based project format: 38 | *.ipr 39 | *.iws 40 | 41 | ## Plugin-specific files: 42 | 43 | # IntelliJ 44 | out/ 45 | 46 | # mpeltonen/sbt-idea plugin 47 | .idea_modules/ 48 | 49 | # JIRA plugin 50 | atlassian-ide-plugin.xml 51 | 52 | # Crashlytics plugin (for Android Studio and IntelliJ) 53 | com_crashlytics_export_strings.xml 54 | crashlytics.properties 55 | crashlytics-build.properties 56 | 57 | 58 | ### Python ### 59 | # Byte-compiled / optimized / DLL files 60 | __pycache__/ 61 | *.py[cod] 62 | 63 | # C extensions 64 | *.so 65 | 66 | # Distribution / packaging 67 | .Python 68 | env/ 69 | build/ 70 | develop-eggs/ 71 | dist/ 72 | downloads/ 73 | eggs/ 74 | lib/ 75 | lib64/ 76 | parts/ 77 | sdist/ 78 | var/ 79 | *.egg-info/ 80 | .installed.cfg 81 | *.egg 82 | 83 | # PyInstaller 84 | # Usually these files are written by a python script from a template 85 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 86 | *.manifest 87 | *.spec 88 | 89 | # Installer logs 90 | pip-log.txt 91 | pip-delete-this-directory.txt 92 | 93 | # Unit test / coverage reports 94 | htmlcov/ 95 | .tox/ 96 | .coverage 97 | .cache 98 | nosetests.xml 99 | coverage.xml 100 | 101 | # Translations 102 | *.mo 103 | *.pot 104 | 105 | # Django stuff: 106 | *.log 107 | 108 | # Sphinx documentation 109 | docs/_build/ 110 | 111 | # PyBuilder 112 | target/ 113 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: yes 3 | 4 | matrix: 5 | include: 6 | - python: 3.6 7 | env: TOXENV=py36-ansible27 8 | - python: 3.6 9 | env: TOXENV=py36-ansible26 10 | - python: 3.6 11 | env: TOXENV=py36-ansible25 12 | - python: 2.7 13 | env: TOXENV=py27-ansible24 14 | - python: 2.7 15 | env: TOXENV=py27-ansible23 16 | - python: 2.7 17 | env: TOXENV=py27-ansible22 18 | - python: 2.7 19 | env: TOXENV=py27-ansible21 20 | - python: 2.7 21 | env: TOXENV=py27-ansible20 22 | 23 | install: 24 | - pip install tox 25 | 26 | script: 27 | - tox 28 | 29 | notifications: 30 | email: false 31 | slack: 32 | template: 33 | - "%{repository_name}@%{branch} %{commit} : [%{build_number}] %{result} " 34 | - "%{build_url}" 35 | - "'%{commit_subject}' by %{author}" 36 | - "%{elapsed_time} : %{duration}" 37 | - "%{message}" 38 | rooms: 39 | secure: NnbcOuvDwjTK1orHxC/LyRhuRZghPt8kliCGBpvBh4exKrr8XjFMoStAOKwu/9KzKDeKzufDTVP4QGNYVp7aQZnTQwJapNTShA47ffAKVAyw9qjGzmOofp3yCo7G9qvAzfeL+E7+4ssnH6Kp1wq1GT79deevl15IjAkzYiRTlUk= 40 | on_success: always 41 | on_failure: always 42 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 43 | 44 | before_cache: 45 | - "find ${HOME}/.pip -name log -o -name __pycache__ -type d | xargs -I {} rm -rf {}" 46 | 47 | cache: 48 | directories: 49 | - "${HOME}/.cache/pip" 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014-2017, ansiblebit 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of ansiblebit nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # primogen 2 | 3 | [![License](https://img.shields.io/badge/license-New%20BSD-blue.svg?style=flat)](https://raw.githubusercontent.com/ansiblebit/primogen/master/LICENSE) 4 | [![Build Status](https://travis-ci.org/ansiblebit/primogen.svg?branch=master)](https://travis-ci.org/ansiblebit/primogen) 5 | 6 | [![Platform](http://img.shields.io/badge/platform-amazon-ff9900.svg?style=flat)](#) 7 | [![Platform](http://img.shields.io/badge/platform-debian-a80030.svg?style=flat)](#) 8 | [![Platform](http://img.shields.io/badge/platform-centos-932279.svg?style=flat)](#) 9 | [![Platform](http://img.shields.io/badge/platform-fedora-3c6eb4.svg?style=flat)](#) 10 | [![Platform](http://img.shields.io/badge/platform-freebsd-ae0000.svg?style=flat)](#) 11 | [![Platform](http://img.shields.io/badge/platform-macosx-000000.svg?style=flat)](#) 12 | [![Platform](http://img.shields.io/badge/platform-mint-87cfbe.svg?style=flat)](#) 13 | [![Platform](http://img.shields.io/badge/platform-opensuse-73ba25.svg?style=flat)](#) 14 | [![Platform](http://img.shields.io/badge/platform-redhat-cc0000.svg?style=flat)](#) 15 | [![Platform](http://img.shields.io/badge/platform-sles-73ba25.svg?style=flat)](#) 16 | [![Platform](http://img.shields.io/badge/platform-smartos-487487.svg?style=flat)](#) 17 | [![Platform](http://img.shields.io/badge/platform-ubuntu-dd4814.svg?style=flat)](#) 18 | [![Platform](http://img.shields.io/badge/platform-windows-004185.svg?style=flat)](#) 19 | 20 | [![Project Stats](https://www.openhub.net/p/ansiblebit-primogen/widgets/project_thin_badge.gif)](https://www.openhub.net/p/ansiblebit-primogen/) 21 | 22 | A brief description of the role goes here. 23 | 24 | 25 | ## Tests 26 | 27 | | Family | Distribution | Version | Test Status | 28 | |:-:|:-:|:-:|:-:| 29 | | Debian | Debian | Jessie | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 30 | | Debian | Debian | Wheezy | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 31 | | Debian | Debian | Stretch | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 32 | | Debian | Ubuntu | Precise | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-passed-006400.svg?style=flat)](#) | 33 | | Debian | Ubuntu | Trusty | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 34 | | Debian | Ubuntu | Vivid | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 35 | | Debian | Ubuntu | Artful | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 36 | | Debian | Ubuntu | Bionic | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 37 | | Debian | Ubuntu | Cosmic | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 38 | | RedHat | CentOS | 6.4 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 39 | | RedHat | CentOS | 6.6 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 40 | | RedHat | Centos | 7 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 41 | | RedHat | Fedora | 20 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 42 | | RedHat | Fedora | 21 | [![x86](http://img.shields.io/badge/x86-n/a-cccccc.svg?style=flat)](#) [![x86_64](http://img.shields.io/badge/x86_64-n/a-cccccc.svg?style=flat)](#) | 43 | 44 | 45 | ## Requirements 46 | 47 | Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. 48 | For instance, if the role uses the EC2 module, 49 | it may be a good idea to mention in this section that the boto package is required. 50 | 51 | - ansible >= 2.0 52 | 53 | 54 | ## Role Variables 55 | 56 | A description of the settable variables for this role should go here, 57 | including any variables that are in defaults/main.yml, vars/main.yml and 58 | any variables that can/should be set via parameters to the role. 59 | 60 | Any variables that are read from other roles and/or 61 | the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. 62 | 63 | - **debug**: flag to run debug tasks. 64 | 65 | 66 | ## Dependencies 67 | 68 | A list of other roles hosted on Galaxy should go here, 69 | plus any details in regards to parameters that may need to be set for other roles 70 | or variables that are used from other roles. 71 | 72 | 73 | ## Playbooks 74 | 75 | Including an example of how to use your role 76 | (for instance, with variables passed in as parameters) 77 | is always nice for users too: 78 | 79 | - hosts: servers 80 | roles: 81 | - { role: username.rolename, x: 42 } 82 | 83 | 84 | ## Tags 85 | 86 | - **configuration**: configuration tasks. 87 | - **debug**: task to debug role variables. 88 | - **installation**: installation tasks. 89 | - **validation**: task to validate role variables. 90 | 91 | 92 | ## Test 93 | 94 | To run the tests you will need to install: 95 | 96 | - [tox](https://tox.readthedocs.org/) 97 | - [vagrant](https://www.vagrantup.com/) 98 | 99 | To run all tests against all pre-defined OS/distributions * ansible versions: 100 | 101 | ``` 102 | $ tox 103 | ``` 104 | 105 | To run tests for `trusty64`: 106 | 107 | ``` 108 | $ cd tests 109 | $ bash test_idempotence.sh --box trusty64.vagrant.dev 110 | # log file will be stores under tests/log 111 | ``` 112 | 113 | To perform debugging on a specific environment: 114 | 115 | ``` 116 | $ cd tests 117 | $ vagrant up trusty64.vagrant.dev 118 | 119 | # to provision using the test.yml playbook (as many time as you need) 120 | $ vagrant provision trusty64.vagrant.dev 121 | 122 | # to access the Vagrant box 123 | $ vagrant ssh trusty64.vagrant.dev 124 | ``` 125 | 126 | 127 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/defaults/main.yml 3 | # 4 | # defaults file 5 | # 6 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/handlers/main.yml 3 | # 4 | # handlers file 5 | # 6 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/meta/main.yml 3 | # 4 | # meta file 5 | # 6 | galaxy_info: 7 | author: First Last 8 | description: Template role. 9 | company: ansiblebit.org 10 | # Some suggested licenses: 11 | # - BSD (default) 12 | # - MIT 13 | # - GPLv2 14 | # - GPLv3 15 | # - Apache 16 | # - CC-BY 17 | license: BSD 18 | min_ansible_version: 1.4.5 19 | # 20 | # Below are all platforms currently available. Just uncomment 21 | # the ones that apply to your role. If you don't see your 22 | # platform on this list, let us know and we'll get it added! 23 | # 24 | platforms: 25 | # - name: AIX 26 | # versions: 27 | # - all 28 | # - any 29 | # - 7.1 30 | # - 6.1 31 | # - 5.3 32 | # - 5.2 33 | # - 5.1 34 | # - 4.3.3 35 | # - 4.3.2 36 | # - 4.3.1 37 | # - 4.3 38 | # - 4.2.1 39 | # - 4.2 40 | # - 4.1.5 41 | # - 4.1.4 42 | # - 4.1.3 43 | # - 4.1.1 44 | # - 4.1 45 | # - 4.0 46 | # - 3.2 47 | # - 3.1 48 | # - 3.0 49 | # - name: Alpine 50 | # versions: 51 | # - all 52 | # - any 53 | # - 3.2 54 | # - 3.1 55 | # - 3.0 56 | # - 2.7 57 | # - 2.6 58 | # - 2.5 59 | # - 2.4 60 | # - 2.3 61 | # - name: Amazon 62 | # versions: 63 | # - all 64 | # - any 65 | # - 2015.03 66 | # - 2014.09 67 | # - 2014.03 68 | # - 2013.09 69 | # - 2013.03 70 | # - 2012.09 71 | # - 2012.03 72 | # - 2011.09 73 | # - name: Archlinux 74 | # versions: 75 | # - all 76 | # - any 77 | # - 2015.05.01 78 | # - 2015.04.01 79 | # - 2015.03.01 80 | # - 2015.02.01 81 | # - 2015.01.01 82 | # - 2014.12.01 83 | # - 2014.11.01 84 | # - 2014.10.01 85 | # - 2014.09.03 86 | # - 2014.08.01 87 | # - 2014.07.03 88 | # - 2014.06.01 89 | # - 2014.05.01 90 | # - 2014.04.01 91 | # - 2014.03.01 92 | # - 2014.02.01 93 | # - 2014.01.05 94 | # - 2013.12.01 95 | # - 2013.11.01 96 | # - 2013.10.01 97 | # - 2013.09.01 98 | # - 2013.08.01 99 | # - 2013.07.01 100 | # - 2013.06.01 101 | # - 2013.05.01 102 | # - 2013.04.02 103 | # - 2013.03.01 104 | # - 2013.02.01 105 | # - 2013.01.04 106 | # - 2012.12.01 107 | # - 2012.11.01 108 | # - 2012.10.06 109 | # - 2012.09.07 110 | # - 2012.08.04 111 | # - 2012.07.15 112 | # - 2011.08.19 113 | # - 2010.05 114 | # - 2009.08 115 | # - 2009.02 116 | # - 2008.06 117 | # - 2007.08-2 118 | # - 2007.08.1 119 | # - 2007.08 120 | # - name: Ascendos 121 | # versions: 122 | # - all 123 | # - any 124 | # - name: CentOS 125 | # versions: 126 | # - all 127 | # - any 128 | # - 7 129 | # - 6 130 | # - 5 131 | # - 4 132 | # - 3 133 | # - name: CloudLinux 134 | # versions: 135 | # - all 136 | # - any 137 | # - name: Debian 138 | # versions: 139 | # - all 140 | # - any 141 | # - jessie 142 | # - wheezy 143 | # - squeeze 144 | # - lenny 145 | # - etch 146 | # - sarge 147 | # - woody 148 | # - potato 149 | # - slink 150 | # - hamm 151 | # - bo 152 | # - rex 153 | # - buzz 154 | # - 0.93R6 155 | # - 0.93R5 156 | # - 0.91 157 | # - name: Fedora 158 | # versions: 159 | # - all 160 | # - any 161 | # - 21 162 | # - 20 163 | # - 19 164 | # - 18 165 | # - 17 166 | # - 16 167 | # - 15 168 | # - 14 169 | # - 13 170 | # - 12 171 | # - 11 172 | # - 10 173 | # - 9 174 | # - 8 175 | # - 7 176 | # - 6 177 | # - 5 178 | # - 4 179 | # - 3 180 | # - 2 181 | # - 1 182 | # - name: FreeBSD 183 | # versions: 184 | # - all 185 | # - any 186 | # - 10.1 187 | # - 10.0 188 | # - 9.3 189 | # - 9.2 190 | # - 9.1 191 | # - 9.0 192 | # - 8.4 193 | # - 8.3 194 | # - 8.2 195 | # - 8.1 196 | # - 8.0 197 | # - 7.4 198 | # - 7.3 199 | # - 7.2 200 | # - 7.1 201 | # - 7.0 202 | # - 6.4 203 | # - 6.3 204 | # - 6.2 205 | # - 6.1 206 | # - 6.0 207 | # - 5.5 208 | # - 5.4 209 | # - 5.3 210 | # - 5.2.1 211 | # - 5.2 212 | # - 5.1 213 | # - 5.0 214 | # - 4.11 215 | # - 4.10 216 | # - 4.9 217 | # - 4.8 218 | # - 4.7 219 | # - 4.6.2 220 | # - 4.6 221 | # - 4.5 222 | # - 4.4 223 | # - 4.3 224 | # - 4.2 225 | # - 4.1.1 226 | # - 4.1 227 | # - 4.0 228 | # - 3.5 229 | # - 3.4 230 | # - 3.3 231 | # - 3.2 232 | # - 3.1 233 | # - 3.0 234 | # - 2.2.8 235 | # - 2.2.7 236 | # - 2.2.6 237 | # - 2.2.5 238 | # - 2.2.2 239 | # - 2.2.1 240 | # - 2.2 241 | # - 2.1.7 242 | # - 2.1.6 243 | # - 2.1.5 244 | # - 2.1 245 | # - 2.0.5 246 | # - 2.0 247 | # - 1.1.5.1 248 | # - 1.1.5 249 | # - 1.1 250 | # - 1.0 251 | # - name: GenericBSD 252 | # versions: 253 | # - all 254 | # - any 255 | # - name: GenericLinux 256 | # versions: 257 | # - all 258 | # - any 259 | # - name: GenericUNIX 260 | # versions: 261 | # - all 262 | # - any 263 | # - name: Gentoo 264 | # versions: 265 | # - all 266 | # - any 267 | # - 20140826 268 | # - 20121221 269 | # - 12.1 270 | # - 12.0 271 | # - 11.0 272 | # - 10.1 273 | # - 10.0 274 | # - 2008 275 | # - 2007 276 | # - 2006.1 277 | # - 2006 278 | # - 2005.1-r1 279 | # - 2005.1 280 | # - 2005.0 281 | # - 2004.3 282 | # - 2004.2 283 | # - 2004.1 284 | # - 2004.0 285 | # - 1.4-r1 286 | # - 1.4 287 | # - 1.2 288 | # - 1.1a 289 | # - 1.0 290 | # - name: HPUX 291 | # versions: 292 | # - all 293 | # - any 294 | # - 11.31 295 | # - 11.23 296 | # - 11.22 297 | # - 11.20 298 | # - 11.11 299 | # - 11.10 300 | # - 11.04 301 | # - 11.00 302 | # - 10.30 303 | # - 10.24 304 | # - 10.20 305 | # - 10.0 306 | # - 9 307 | # - 8 308 | # - 7 309 | # - 6 310 | # - 5.0 311 | # - 3 312 | # - 2.0 313 | # - 1.0 314 | # - name: MacOSX 315 | # versions: 316 | # - all 317 | # - any 318 | # - 10.10 319 | # - 10.9 320 | # - 10.8 321 | # - 10.7 322 | # - 10.6 323 | # - name: Mandrake 324 | # versions: 325 | # - all 326 | # - any 327 | # - 2011 328 | # - 2010 329 | # - 2009 330 | # - 2007 331 | # - 2006 332 | # - 10 333 | # - 9 334 | # - 8 335 | # - 7 336 | # - 6 337 | # - 5 338 | # - name: Mandriva 339 | # versions: 340 | # - all 341 | # - any 342 | # - 2011 343 | # - 2010 344 | # - 2009 345 | # - 2007 346 | # - 2006 347 | # - 10 348 | # - 9 349 | # - 8 350 | # - 7 351 | # - 6 352 | # - 5 353 | # - name: Nexenta 354 | # versions: 355 | # - all 356 | # - any 357 | # - 1 358 | # - name: OEL # Oracle Enterprise Linux or Oracle Linux 359 | # versions: 360 | # - all 361 | # - any 362 | # - name: OVS 363 | # versions: 364 | # - all 365 | # - any 366 | # - 2.3 367 | # - 2.1 368 | # - 2.0 369 | # - 1.11 370 | # - 1.10 371 | # - 1.9 372 | # - 1.7 373 | # - 1.6 374 | # - 1.5 375 | # - 1.4 376 | # - 1.3 377 | # - 1.2 378 | # - 1.1 379 | # - 1.0 380 | # - 0.99 381 | # - 0.90 382 | # - name: OmniOS 383 | # versions: 384 | # - all 385 | # - any 386 | # - r151014 387 | # - r151012 388 | # - r151010 389 | # - r151008 390 | # - r151006 391 | # - r151004 392 | # - r151002 393 | # - name: OpenIndiana 394 | # versions: 395 | # - all 396 | # - any 397 | # - name: OpenSuSE 398 | # versions: 399 | # - all 400 | # - any 401 | # - 13.2 402 | # - 13.1 403 | # - 12.3 404 | # - 12.2 405 | # - 12.1 406 | # - 11.4 407 | # - 11.3 408 | # - 11.2 409 | # - 11.1 410 | # - 10.3 411 | # - 10.2 412 | # - 10.1 413 | # - 10.0 414 | # - name: OracleLinux 415 | # versions: 416 | # - all 417 | # - any 418 | # - 7.1 419 | # - 7.0 420 | # - 6.6 421 | # - 6.5 422 | # - 6.4 423 | # - 6.3 424 | # - 6.2 425 | # - 6.1 426 | # - 6.0 427 | # - 5.11 428 | # - 5.10 429 | # - 5.9 430 | # - 5.8 431 | # - 5.7 432 | # - 5.6 433 | # - 5.5 434 | # - 5.4 435 | # - 5.3 436 | # - 5.2 437 | # - 5.1 438 | # - 5.0 439 | # - 4.9 440 | # - 4.8 441 | # - 4.7 442 | # - 4.6 443 | # - 4.5 444 | # - name: PSBM 445 | # versions: 446 | # - all 447 | # - any 448 | # - name: RedHat 449 | # versions: 450 | # - all 451 | # - any 452 | # - 7 453 | # - 6 454 | # - 5 455 | # - 4 456 | # - 3 457 | # - 2.1 458 | # - name: SLC # CERN Scientific Linux 459 | # versions: 460 | # - all 461 | # - any 462 | # - 7.3 463 | # - 7 464 | # - 6.1 465 | # - 6 466 | # - 5 467 | # - 4 468 | # - 3 469 | # - name: SLED # Suse Linux Enterprise Desktop 470 | # versions: 471 | # - all 472 | # - any 473 | # - 12 474 | # - 11SP3 475 | # - 11SP2 476 | # - 11SP1 477 | # - 11 478 | # - 10SP4 479 | # - 10SP3 480 | # - 10SP2 481 | # - 10SP1 482 | # - 10 483 | # - name: SLES # Suse Linux Enterprise Server 484 | # versions: 485 | # - all 486 | # - any 487 | # - 12 488 | # - 11SP3 489 | # - 11SP2 490 | # - 11SP1 491 | # - 11 492 | # - 10SP4 493 | # - 10SP3 494 | # - 10SP2 495 | # - 10SP1 496 | # - 10 497 | # - 9SP4 498 | # - 9SP3 499 | # - 9SP2 500 | # - 9SP1 501 | # - 9 502 | # - 8SP4 503 | # - 8SP3 504 | # - 8SP2a 505 | # - 8SP2 506 | # - 8SP1 507 | # - 8 508 | # - 7 509 | # - name: Scientific # or SL or Scientific Linux 510 | # versions: 511 | # - all 512 | # - any 513 | # - 7 514 | # - 6 515 | # - 5 516 | # - name: SmartOS 517 | # versions: 518 | # - all 519 | # - any 520 | # - name: Solaris 521 | # versions: 522 | # - all 523 | # - any 524 | # - 11.2 525 | # - 11.1 526 | # - 11 527 | # - 11-2010.11 528 | # - 10 529 | # - 9 530 | # - 8 531 | # - 2.6 532 | # - 2.5.1 533 | # - 2.5 534 | # - 2.4 535 | # - 2.3 536 | # - 2.2 537 | # - 2.1 538 | # - 2.0 539 | # - 1 540 | # - name: SuSE 541 | # versions: 542 | # - all 543 | # - any 544 | # - 12.0 545 | # - 11.3 546 | # - 11.2 547 | # - 11.1 548 | # - 11 549 | # - 10.4 550 | # - 10.3 551 | # - 10.2 552 | # - 10.1 553 | # - 10 554 | # - 9.3 555 | # - 9.2 556 | # - 9.1 557 | # - 9.0 558 | # - 8.2 559 | # - 8.1 560 | # - 8.0 561 | # - 7.3 562 | # - 7.2 563 | # - 7.1 564 | # - 7.0 565 | # - 6.4 566 | # - 6.3 567 | # - 6.2 568 | # - 6.1 569 | # - 6.0 570 | # - 5.3 571 | # - 5.2 572 | # - 5.1 573 | # - 5.0 574 | # - 4.4.1 575 | # - 4.4 576 | # - 4.3 577 | # - 4.2 578 | # - 11/95 579 | # - 8/95 580 | # - 4/95 581 | # - 11/94 582 | # - 7/94 583 | # - 3/94 584 | - name: Ubuntu 585 | versions: 586 | # - all 587 | # - any 588 | # - vivid 589 | # - utopic 590 | # - trusty 591 | # - saucy 592 | # - raring 593 | # - quantal 594 | - precise 595 | # - oneiric 596 | # - natty 597 | # - maverick 598 | # - lucid 599 | # - karmic 600 | # - jaunty 601 | # - intrepid 602 | # - hardy 603 | # - gutsy 604 | # - feisty 605 | # - edgy 606 | # - dapper 607 | # - breezy 608 | # - hoary 609 | # - warty 610 | # - name: XenServer 611 | # versions: 612 | # - all 613 | # - any 614 | # - 4.5 615 | # - 4.4 616 | # - 4.3 617 | # - 4.2 618 | # - 4.1 619 | # - 4.0 620 | # - 3.4 621 | # - 3.3 622 | # - 3.2 623 | # - 3.1 624 | # - 3.0 625 | # - 2.0 626 | # - 1.0 627 | # Below are all categories currently available. Just as with 628 | # the platforms above, uncomment those that apply to your role. 629 | # 630 | galaxy_tags: 631 | #- cloud 632 | #- cloud:ec2 633 | #- cloud:gce 634 | #- cloud:rax 635 | #- clustering 636 | #- database 637 | #- database:nosql 638 | #- database:sql 639 | - development 640 | #- monitoring 641 | #- networking 642 | #- packaging 643 | #- system 644 | #- web 645 | dependencies: [] 646 | # List your role dependencies here, one per line. Only 647 | # dependencies available via galaxy should be listed here. 648 | # Be sure to remove the '[]' above if you add dependencies 649 | # to this list. 650 | -------------------------------------------------------------------------------- /requirements.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansiblebit/primogen/ea5008f64cc3c14988e6f66933aa773a12faff25/requirements.yml -------------------------------------------------------------------------------- /tasks/debug.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: tasks/debug.yml 3 | # 4 | # debug tasks. 5 | # 6 | 7 | - debug: 8 | var="{{ item }}" 9 | when: "{{ item }} is defined" 10 | with_items: 11 | - debug 12 | 13 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/tasks/main.yml 3 | # 4 | # tasks file 5 | # 6 | 7 | - include: debug.yml 8 | when: debug | default(false) 9 | tags: debug 10 | 11 | - include: validation.yml 12 | tags: validation 13 | 14 | - debug: > 15 | msg="invoked" 16 | 17 | -------------------------------------------------------------------------------- /tasks/validation.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/tasks/validation.yml 3 | # 4 | # validation tasks. 5 | # 6 | 7 | - name: ensure mandatory variables are set 8 | fail: 9 | msg="{{ item }} is a mandatory variable" 10 | when: "{{ item }} is not defined" 11 | with_items: 12 | - debug 13 | 14 | -------------------------------------------------------------------------------- /tests/Vagrantfile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'yaml' 4 | 5 | PLAYBOOK = 'test.yml' 6 | CONFIGURATION_FILE = 'boxes.yml' 7 | ROLE_NAME = "#{File.expand_path("..").split("/")[-1]}" 8 | 9 | Vagrant.configure('2') do |config| 10 | 11 | # overcome 'stdin: is not a tty' errors when trying to provision on vivid64 12 | config.ssh.pty = true 13 | config.ssh.shell = 'bash' 14 | 15 | # puts "[DEBUG] loading box settings from #{CONFIGURATION_FILE}..." 16 | vagrant_environment = YAML.load_file(File.expand_path(CONFIGURATION_FILE, File.dirname(__FILE__))) 17 | 18 | vagrant_environment['vagrant'].each do |box_name, box_settings| 19 | if not box_settings['enabled'] 20 | # puts "[DEBUG] #{box_name} is not enabled. skipping..." 21 | next 22 | end 23 | 24 | # puts "[DEBUG] applying #{box_name} settings..." 25 | config.vm.define box_name do |host| 26 | 27 | host.vm.box = box_settings['box'] unless not box_settings.key? 'box' 28 | host.vm.box_version = box_settings['box_version'] unless not box_settings.key? 'box_version' 29 | 30 | host.vm.network box_settings['network']['name'], ip: box_settings['network']['ip'] unless box_settings.key? 'network' 31 | host.vm.synced_folder '.', '/vagrant', disabled: true 32 | 33 | # puts "[DEBUG] applying virtualbox settings for #{box_name} box..." 34 | customize_args = [ "modifyvm", :id ] 35 | vagrant_environment['provider']['virtualbox'].collect { |k, v| customize_args |= ["--#{k}", v.to_s] } 36 | host.vm.provider 'virtualbox' do |vb| 37 | vb.name = "#{ROLE_NAME}_#{box_name}" 38 | vb.customize customize_args 39 | end 40 | 41 | # puts "[DEBUG] provision using ansible vagrant playbook..." 42 | host.vm.provision 'ansible' do |ansible| 43 | 44 | ansible.host_vars = { 45 | 'xenial64.vagrant.dev' => { 46 | 'ansible_python_interpreter' => '/usr/bin/python2.7', 47 | 'playbook_python2' => true 48 | }, 49 | 'yakkety64.vagrant.dev' => { 50 | 'ansible_python_interpreter' => '/usr/bin/python2.7', 51 | 'playbook_python2' => true 52 | }, 53 | 'artful64.vagrant.dev' => { 54 | 'ansible_python_interpreter' => '/usr/bin/python2.7', 55 | 'playbook_python2' => true 56 | }, 57 | 'bionic64.vagrant.dev' => { 58 | 'ansible_python_interpreter' => '/usr/bin/python2.7', 59 | 'playbook_python2' => true 60 | }, 61 | 'cosmic64.vagrant.dev' => { 62 | 'ansible_python_interpreter' => '/usr/bin/python2.7', 63 | 'playbook_python2' => true 64 | }, 65 | } 66 | 67 | ansible.playbook = PLAYBOOK 68 | ansible.verbose = 'v' 69 | ansible.skip_tags = 'test' 70 | ansible.extra_vars = { 71 | 'env': 'vagrant', 72 | 'vagrant_box': "#{box_name}" 73 | } 74 | end 75 | end 76 | end 77 | end 78 | 79 | -------------------------------------------------------------------------------- /tests/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | ansible_managed = Ansible managed file, do not edit directly 3 | callback_plugins = plugins/callback 4 | 5 | host_key_checking = False 6 | 7 | private_key_file = ~/.vagrant.d/insecure_private_key 8 | 9 | roles_path = ../../:../ 10 | -------------------------------------------------------------------------------- /tests/boxes.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/tests/boxes.yml 3 | # 4 | 5 | provider: 6 | virtualbox: 7 | memory: 1024 8 | cpus: 1 9 | 10 | 11 | vagrant: 12 | 13 | 14 | # CentOS 15 | 16 | centos64-64.vagrant.dev: 17 | enabled: false 18 | box: hansode/centos-6.4-x86_64 19 | network: 20 | name: private_network 21 | ip: 192.168.121.1 22 | 23 | centos66-64.vagrant.dev: 24 | enabled: false 25 | box: hansode/centos-6.6-x86_64 26 | network: 27 | name: private_network 28 | ip: 192.168.121.2 29 | 30 | centos7-64.vagrant.dev: 31 | enabled: false 32 | box: centos/7 33 | network: 34 | name: private_network 35 | ip: 192.168.121.3 36 | 37 | 38 | # Debian 39 | 40 | jessie64.vagrant.dev: 41 | enabled: false 42 | box: debian/jessie64 43 | network: 44 | name: private_network 45 | ip: 192.168.122.1 46 | 47 | wheezy64.vagrant.dev: 48 | enabled: false 49 | box: debian/wheezy64 50 | network: 51 | name: private_network 52 | ip: 192.168.122.2 53 | 54 | stretch64.vagrant.dev: 55 | enabled: false 56 | box: debian/stretch64 57 | network: 58 | name: private_network 59 | ip: 192.168.122.3 60 | 61 | 62 | # Fedora 63 | 64 | fedora20-32.vagrant.dev: 65 | enabled: false 66 | box: hansode/fedora-20-i386 67 | network: 68 | name: private_network 69 | ip: 192.168.123.1 70 | 71 | fedora20-64.vagrant.dev: 72 | enabled: false 73 | box: hansode/fedora-20-x86_64 74 | network: 75 | name: private_network 76 | ip: 192.168.123.2 77 | 78 | fedora21-32.vagrant.dev: 79 | enabled: false 80 | box: hansode/fedora-21-i386 81 | network: 82 | name: private_network 83 | ip: 192.168.123.3 84 | 85 | fedora21-64.vagrant.dev: 86 | enabled: false 87 | box: hansode/fedora-21-x86_64 88 | network: 89 | name: private_network 90 | ip: 192.168.123.4 91 | 92 | fedora23-atomic.vagrant.dev: 93 | enabled: false 94 | box: fedora/23-atomic-host 95 | network: 96 | name: private_network 97 | ip: 192.168.123.5 98 | 99 | fedora23-cloud.vagrant.dev: 100 | enabled: false 101 | box: fedora/23-cloud-base 102 | network: 103 | name: private_network 104 | ip: 192.168.123.6 105 | 106 | 107 | # OpenSUSE 108 | 109 | leap64.vagrant.dev: 110 | enabled: false 111 | box: opensuse/openSUSE-42.1-x86_64 112 | network: 113 | name: private_network 114 | ip: 192.168.125.2 115 | 116 | tumbleweed64.vagrant.dev: 117 | enabled: false 118 | box: opensuse/openSUSE-Tumbleweed-x86_64 119 | network: 120 | name: private_network 121 | ip: 192.168.125.4 122 | 123 | 124 | # Ubuntu 125 | 126 | precise32.vagrant.dev: 127 | enabled: false 128 | box: ubuntu/precise32 129 | network: 130 | name: private_network 131 | ip: 192.168.124.1 132 | 133 | precise64.vagrant.dev: 134 | enabled: false 135 | box: ubuntu/precise64 136 | network: 137 | name: private_network 138 | ip: 192.168.124.2 139 | 140 | trusty32.vagrant.dev: 141 | enabled: false 142 | box: ubuntu/trusty32 143 | network: 144 | name: private_network 145 | ip: 192.168.124.3 146 | 147 | trusty64.vagrant.dev: 148 | enabled: false 149 | box: ubuntu/trusty64 150 | network: 151 | name: private_network 152 | ip: 192.168.124.4 153 | 154 | vivid32.vagrant.dev: 155 | enabled: false 156 | box: ubuntu/vivid32 157 | network: 158 | name: private_network 159 | ip: 192.168.124.5 160 | 161 | vivid64.vagrant.dev: 162 | enabled: false 163 | box: ubuntu/vivid64 164 | network: 165 | name: private_network 166 | ip: 192.168.124.6 167 | 168 | wily64.vagrant.dev: 169 | enabled: true 170 | box: ubuntu/wily64 171 | network: 172 | name: private_network 173 | ip: 192.168.124.7 174 | 175 | xenial64.vagrant.dev: 176 | enabled: true 177 | box: ubuntu/xenial64 178 | network: 179 | name: private_network 180 | ip: 192.168.124.8 181 | 182 | yakkety64.vagrant.dev: 183 | enabled: true 184 | box: ubuntu/yakkety64 185 | network: 186 | name: private_network 187 | ip: 192.168.124.9 188 | 189 | artful64.vagrant.dev: 190 | enabled: true 191 | box: ubuntu/artful64 192 | network: 193 | name: private_network 194 | ip: 192.168.124.10 195 | 196 | bionic64.vagrant.dev: 197 | enabled: true 198 | box: ubuntu/bionic64 199 | network: 200 | name: private_network 201 | ip: 192.168.124.11 202 | 203 | cosmic64.vagrant.dev: 204 | enabled: true 205 | box: ubuntu/cosmic64 206 | network: 207 | name: private_network 208 | ip: 192.168.124.12 209 | -------------------------------------------------------------------------------- /tests/log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansiblebit/primogen/ea5008f64cc3c14988e6f66933aa773a12faff25/tests/log/.gitkeep -------------------------------------------------------------------------------- /tests/plugins/callback/idempotence.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from __future__ import (absolute_import, print_function) 4 | 5 | import sys 6 | import os 7 | 8 | from ansible import constants as C 9 | from ansible.constants import mk_boolean 10 | 11 | try: 12 | from ansible.plugins.callback import CallbackBase 13 | parent = CallbackBase 14 | except ImportError: 15 | parent = object 16 | 17 | 18 | VAR_IDEMPOTENCE = u'IDEMPOTENCE' 19 | 20 | 21 | class CallbackModule(parent): 22 | """ 23 | This callback module performs the idempotency test whenever the 'idempotency' variable is set to True. 24 | """ 25 | CALLBACK_VERSION = 2.0 26 | CALLBACK_NAME = 'idempotency' 27 | 28 | def __init__(self): 29 | self.playbook = None 30 | self.enabled = mk_boolean(os.getenv(VAR_IDEMPOTENCE, 'no')) 31 | 32 | super(CallbackModule, self).__init__() 33 | 34 | def playbook_on_stats(self, stats): 35 | 36 | if self.enabled: 37 | if len(stats.dark) > 0: 38 | self._display.warning('idempotency test failed: unreachable=%s > 0' % stats.dark) 39 | sys.exit(os.EX_SOFTWARE) 40 | if len(stats.changed) > 0: 41 | self._display.warning('idempotency test failed: changed=%s > 0' % stats.changed) 42 | sys.exit(os.EX_SOFTWARE) 43 | if len(stats.failures) > 0: 44 | self._display.warning('idempotency test failed: failures=%s > 0' % stats.failures) 45 | sys.exit(os.EX_SOFTWARE) 46 | 47 | def v2_playbook_on_stats(self, stats): 48 | """Verify that playbook ran without any changes or failures.""" 49 | self.playbook_on_stats(stats) 50 | 51 | -------------------------------------------------------------------------------- /tests/roles/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ansiblebit/primogen/ea5008f64cc3c14988e6f66933aa773a12faff25/tests/roles/.gitkeep -------------------------------------------------------------------------------- /tests/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ################# 3 | # 4 | # Bash script to setup the test environment. 5 | # 6 | # version: 1.0 7 | # 8 | # usage: 9 | # 10 | # setup.sh 11 | # 12 | # example: 13 | # 14 | # bash setup.sh 15 | # 16 | # changelog: 17 | # 18 | # v1.0 : 10 June 2016 19 | # - initial version 20 | # 21 | # author(s): 22 | # - Pedro Salgado 23 | # 24 | # ################# 25 | 26 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 27 | 28 | test -s ${DIR}/../requirements.yml \ 29 | && ansible-galaxy install \ 30 | --force \ 31 | -r ${DIR}/../requirements.yml \ 32 | --roles-path=${DIR}/roles \ 33 | || true 34 | -------------------------------------------------------------------------------- /tests/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/tests/tasks 3 | # 4 | # Test tasks to verify role execution. 5 | # 6 | 7 | - debug: 8 | msg="You need to define tests here!" 9 | tags: 10 | - debug 11 | - test 12 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # file: primogen/tests/test.yml 3 | 4 | - name: setup python2 5 | hosts: "{{ vagrant_box }}" 6 | gather_facts: no 7 | 8 | tasks: 9 | - raw: sudo apt-get update -qq && sudo apt-get install -qq python2.7 10 | changed_when: no 11 | when: playbook_python2 is defined and 12 | playbook_python2 13 | 14 | 15 | - name: tests play 16 | hosts: "{{ vagrant_box }}" 17 | gather_facts: yes 18 | 19 | vars: 20 | debug: yes 21 | 22 | roles: 23 | - role: primogen 24 | 25 | - role: tests 26 | tags: test 27 | 28 | -------------------------------------------------------------------------------- /tests/test_checkmode.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ################# 3 | # 4 | # Bash script to run check mode tests. 5 | # 6 | # version: 1.5 7 | # 8 | # usage: 9 | # 10 | # test_checkmode [options] 11 | # 12 | # options: 13 | # 14 | # --box The name of the Vagrant box or host name 15 | # --env The name of the test environment 16 | # --inventory The Ansible inventory in the form of a file or string "host," 17 | # --playbook The path to the Ansible test playbook 18 | # 19 | # example: 20 | # 21 | # # on localhost 22 | # bash test_checkmode.sh 23 | # 24 | # # on a Vagrant box 25 | # bash test_checkmode.sh \ 26 | # --box precise64.vagrant.dev \ 27 | # --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory 28 | # 29 | # 30 | # changelog: 31 | # 32 | # v1.5 : 8 Mar 2016 33 | # - pass vagrant_box variable to playbook 34 | # - default inventory changed from localhost to match what Vagrant provisioner generates 35 | # v1.4 : 10 Jul 2015 36 | # - added extra variables to force running idempotence tests on vagrant 37 | # v1.2 38 | # - added env option 39 | # 40 | # author(s): 41 | # - Pedro Salgado 42 | # 43 | # ################# 44 | 45 | 46 | # GREEN : SGR code to set text color (foreground) to green. 47 | GREEN='\033[0;32m' 48 | # RED : SGR code to set text color (foreground) to red. 49 | RED='\033[0;31m' 50 | # SGR code to set text color (foreground) to no color. 51 | NC='\033[0m' 52 | # The idempotence pass criteria. 53 | PASS_CRITERIA="changed=0.* unreachable=0.* failed=0" 54 | 55 | # the name of the virtualenv 56 | VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }') 57 | 58 | 59 | while [[ $# > 1 ]] 60 | do 61 | key="$1" 62 | 63 | case $key in 64 | 65 | --box) 66 | # the name of the Vagrant box or host name 67 | BOX="$2" 68 | shift;; 69 | 70 | --env) 71 | # the test environment 72 | ENV="$2" 73 | shift;; 74 | 75 | --inventory) 76 | # the Ansible inventory in the form of a file or string "host," 77 | INVENTORY="$2" 78 | shift;; 79 | 80 | --playbook) 81 | # the path to the Ansible test playbook 82 | PLAYBOOK="$2" 83 | shift;; 84 | 85 | *) 86 | # unknown option 87 | ;; 88 | 89 | esac 90 | shift 91 | done 92 | 93 | # the name of the Vagrant box or host name 94 | BOX=${BOX:-localhost} 95 | # the Ansible inventory 96 | INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'} 97 | # the path to the Ansible test playbook 98 | PLAYBOOK=${PLAYBOOK:-test.yml} 99 | # the logfile to hold the output of the playbook run 100 | LOGFILE="log/${BOX}_checkmode_${VIRTUALENV_NAME}.log" 101 | 102 | EXTRA_ARGS='' 103 | if [ $BOX == "localhost" ]; then 104 | INVENTORY='localhost,' 105 | EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost --skip-tags=test" 106 | else 107 | EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX} --skip-tags=test" 108 | fi 109 | 110 | echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running checkmode test..." 111 | ansible-playbook -vvvv --check --diff -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \ 112 | tee ${LOGFILE} | \ 113 | grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \ 114 | echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${GREEN}PASS${NC}\n" || ( \ 115 | cat ${LOGFILE} && 116 | echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} checkmode : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \ 117 | exit 1) 118 | 119 | -------------------------------------------------------------------------------- /tests/test_idempotence.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ################# 3 | # 4 | # Bash script to run idempotence tests. 5 | # 6 | # version: 1.5 7 | # 8 | # usage: 9 | # 10 | # test_idempotence [options] 11 | # 12 | # options: 13 | # 14 | # --box The name of the Vagrant box or host name 15 | # --env The name of the test environment 16 | # --inventory The Ansible inventory in the form of a file or string "host," 17 | # --playbook The path to the Ansible test playbook 18 | # 19 | # example: 20 | # 21 | # # on localhost 22 | # bash test_idempotence.sh 23 | # 24 | # # on a Vagrant box 25 | # bash test_idempotence.sh \ 26 | # --box precise64.vagrant.dev \ 27 | # --inventory .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory 28 | # 29 | # 30 | # changelog: 31 | # 32 | # v1.5 : 8 Mar 2016 33 | # - pass vagrant_box variable to playbook 34 | # - default inventory changed from localhost to match what Vagrant provisioner generates 35 | # v1.4 : 10 Jul 2015 36 | # - added extra variables to force running idempotence tests on vagrant 37 | # v1.2 38 | # - added env option 39 | # 40 | # author(s): 41 | # - Pedro Salgado 42 | # 43 | # ################# 44 | 45 | 46 | # GREEN : SGR code to set text color (foreground) to green. 47 | GREEN='\033[0;32m' 48 | # RED : SGR code to set text color (foreground) to red. 49 | RED='\033[0;31m' 50 | # SGR code to set text color (foreground) to no color. 51 | NC='\033[0m' 52 | # The idempotence pass criteria. 53 | PASS_CRITERIA="changed=0.* unreachable=0.* failed=0" 54 | 55 | # the name of the virtualenv 56 | VIRTUALENV_NAME=$(which python | awk -F / 'NF && NF-2 { print ( $(NF-2) ) }') 57 | 58 | 59 | while [[ $# > 1 ]] 60 | do 61 | key="$1" 62 | 63 | case $key in 64 | 65 | --box) 66 | # the name of the Vagrant box or host name 67 | BOX="$2" 68 | shift;; 69 | 70 | --env) 71 | # the test environment 72 | ENV="$2" 73 | shift;; 74 | 75 | --inventory) 76 | # the Ansible inventory in the form of a file or string "host," 77 | INVENTORY="$2" 78 | shift;; 79 | 80 | --playbook) 81 | # the path to the Ansible test playbook 82 | PLAYBOOK="$2" 83 | shift;; 84 | 85 | *) 86 | # unknown option 87 | ;; 88 | 89 | esac 90 | shift 91 | done 92 | 93 | # the name of the Vagrant box or host name 94 | BOX=${BOX:-localhost} 95 | # the Ansible inventory 96 | INVENTORY=${INVENTORY:-'.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory'} 97 | # the path to the Ansible test playbook 98 | PLAYBOOK=${PLAYBOOK:-test.yml} 99 | # the logfile to hold the output of the playbook run 100 | LOGFILE="log/${BOX}_idempotence_${VIRTUALENV_NAME}.log" 101 | 102 | EXTRA_ARGS='' 103 | if [ $BOX == "localhost" ]; then 104 | INVENTORY='localhost,' 105 | EXTRA_ARGS="--connection=local -e env=${ENV} -e vagrant_box=localhost" 106 | else 107 | EXTRA_ARGS="--user vagrant -e env=vagrant -e vagrant_box=${BOX}" 108 | fi 109 | 110 | echo "[INFO] ${BOX} ${VIRTUALENV_NAME} running idempotence test..." 111 | IDEMPOTENCE='yes' \ 112 | ansible-playbook -vvvv -i ${INVENTORY} --limit ${BOX}, ${EXTRA_ARGS} ${PLAYBOOK} 2>&1 | \ 113 | tee ${LOGFILE} | \ 114 | grep "${BOX}" | grep -q "${PASS_CRITERIA}" && \ 115 | echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${GREEN}PASS${NC}\n" || ( \ 116 | cat ${LOGFILE} && 117 | echo -ne "[TEST] ${BOX} ${VIRTUALENV_NAME} idempotence : ${RED}FAILED${NC} ${PASS_CRITERIA}\n" && \ 118 | exit 1) 119 | 120 | -------------------------------------------------------------------------------- /tests/travis.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ################# 3 | # 4 | # Bash script to run tests in the travis-ci environment. 5 | # 6 | # version: 1.0 7 | # 8 | # usage: 9 | # 10 | # travis.sh 11 | # 12 | # example: 13 | # 14 | # bash travis.sh 15 | # 16 | # changelog: 17 | # 18 | # v1.0 : 10 June 2016 19 | # - initial version 20 | # 21 | # author(s): 22 | # - Pedro Salgado 23 | # 24 | # ################# 25 | 26 | test $USER != 'travis' && exit 0 27 | 28 | set -e 29 | 30 | ansible-playbook \ 31 | -i localhost, \ 32 | --connection=local test.yml \ 33 | -e vagrant_box=localhost \ 34 | -e env=travis \ 35 | --skip-tags=test \ 36 | $@ \ 37 | && bash test_idempotence.sh \ 38 | --env travis \ 39 | && bash test_checkmode.sh \ 40 | --env travis 41 | -------------------------------------------------------------------------------- /tests/vagrant.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ################# 3 | # 4 | # Bash script to run the test suite against the Vagrant environment. 5 | # 6 | # version: 1.8 7 | # 8 | # usage: 9 | # 10 | # # run tests against all enabled Vagrant boxes 11 | # $ bash vagrant.sh 12 | # 13 | # # run tests against a single Vagrant box 14 | # $ bash vagrant.sh --box precise64.vagrant.dev 15 | # 16 | # 17 | # changelog: 18 | # 19 | # v1.8 : 10 August 2016 20 | # - force provisioning 21 | # 22 | # v1.6 : 10 Jun 2016 23 | # - exit if USER environment variable is travis 24 | # 25 | # v1.4 : 10 Jul 2015 26 | # - remove environment variable ANSIBLE_ASK_SUDO_PASS 27 | # 28 | # author(s): 29 | # - Pedro Salgado 30 | # 31 | # ################# 32 | 33 | test $USER == 'travis' && exit 0 34 | 35 | DIR="$(dirname "$0")" 36 | 37 | cd $DIR 38 | 39 | # the path to the Ansible inventory generated by Vagrant 40 | INVENTORY=${DIR}/.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory 41 | 42 | 43 | while [[ $# > 1 ]] 44 | do 45 | key="$1" 46 | 47 | case $key in 48 | 49 | --box) 50 | # the name of the Vagrant box to run tests against 51 | BOX="$2" 52 | shift;; 53 | 54 | *) 55 | # unknown option 56 | ;; 57 | 58 | esac 59 | shift 60 | done 61 | 62 | for VAGRANT_BOX in `grep vagrant.dev boxes.yml | sed 's/://g'` 63 | do 64 | if [ ! -n "${BOX+1}" ] || [ "${BOX}" = "${VAGRANT_BOX}" ]; then 65 | 66 | echo "[INFO] preparing ${VAGRANT_BOX}..." 67 | vagrant up --provision ${VAGRANT_BOX} 2> /dev/null 68 | if [ $? -ne 0 ]; then 69 | # box not enabled 70 | continue 71 | fi 72 | 73 | bash ${DIR}/test_idempotence.sh --box ${VAGRANT_BOX} --inventory $INVENTORY 74 | bash ${DIR}/test_checkmode.sh --box ${VAGRANT_BOX} --inventory $INVENTORY 75 | 76 | echo "[INFO] destroy ${VAGRANT_BOX}..." 77 | vagrant destroy -f ${VAGRANT_BOX} 78 | fi 79 | done 80 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | py{36,27}-ansible{28,27,26,25,24,23,22,21,20,19} 4 | 5 | skipsdist = True 6 | 7 | 8 | [testenv] 9 | changedir = tests 10 | 11 | deps = 12 | ansible28: ansible>=2.8,<2.9 13 | ansible27: ansible>=2.7,<2.8 14 | ansible26: ansible>=2.6,<2.7 15 | ansible25: ansible>=2.5,<2.6 16 | ansible24: ansible>=2.4,<2.5 17 | ansible23: ansible>=2.3,<2.4 18 | ansible22: ansible>=2.2,<2.3 19 | ansible21: ansible>=2.1,<2.2 20 | ansible20: ansible>=2.0.0,<2.1 21 | ansible19: ansible>=1.9,<2.0.0 22 | 23 | passenv = ANSIBLE_ASK_SUDO_PASS HOME LANG LC_ALL TRAVIS USER 24 | 25 | commands = 26 | bash setup.sh 27 | bash travis.sh {posargs} 28 | bash vagrant.sh {posargs} 29 | 30 | whitelist_externals = 31 | ansible-playbook 32 | bash 33 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file 3 | --------------------------------------------------------------------------------