Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement a test infrastructure #6

Open
ferrarimarco opened this issue Jan 27, 2017 · 11 comments
Open

Implement a test infrastructure #6

ferrarimarco opened this issue Jan 27, 2017 · 11 comments

Comments

@ferrarimarco
Copy link
Contributor

Currently generated roles do not include any test facility.

I'll provide a pull request that implements testing with Test-Kitchen configured with the kitchen-docker driver,
and kitchen-inspec.

Let's talk about this :)

@pgporada
Copy link

pgporada commented Feb 7, 2017

I personally use this Gemfile and this .kitchen.yml to test my ansible roles.

Gemfile

source "https://rubygems.org"

gem "test-kitchen"
gem "kitchen-vagrant"
gem "vagrant-wrapper"
gem "kitchen-ansible"
gem "busser-bats"
gem "kitchen-sync"

.kitchen.yml

---
driver:
  name: vagrant
  use_sudo: false
  forward_agent: true

provisioner:
  hosts: test-kitchen
  name: ansible_playbook
  require_ansible_repo: true
  ansible_yum_repo: epel
  require_ansible_omnibus: false
  ansible_verbosity: 2
  ansible_verbose: true
  ansible_diff: true
  require_chef_for_busser: true
  update_package_repos: false
  requirements_path: test/requirements.yml
  ssh_known_hosts:
    - bitbucket.org

platforms:
  - name: centos-7
    driver:
      box: centos/7
      provision: true
      vagrantfiles:
        - .vagrant.rb
      network:
        - ["private_network", {ip: "192.168.33.102"}]

suites:
  - name: default

transport:
  forward_agent: true
  name: rsync
...

.vagrant.rb

Vagrant.configure(2) do |config|
    config.vm.provision "shell", inline: "sudo systemctl restart network.service || true", run: "always"
    config.vm.provision "shell", inline: <<-SHELL
        sudo yum install -y epel-release git vim telnet net-tools rsync
        sudo yum update -y epel-release
        sudo yum install -y ansible
    SHELL
end

Instead of inspec, I use BATS because $REASONS.

@pgporada
Copy link

pgporada commented Feb 7, 2017

@ferrarimarco Do you use a tool such as yamllint?

If not, here is my config

---
extends: default

rules:
  line-length:
    max: 80
    level: warning
  document-start:
    present: true
  document-end:
    present: true
  key-duplicates: enable
  trailing-spaces: enable
  new-line-at-end-of-file: disable
  hyphens:
    max-spaces-after: 1
  empty-lines:
    max: 2
    max-start: 0
    max-end: 0
  commas:
    max-spaces-before: 0
    min-spaces-after: 1
    max-spaces-after: 1
  colons:
    max-spaces-before: 0
    max-spaces-after: 1
  brackets:
    min-spaces-inside: 0
    max-spaces-inside: 0
  braces:
    min-spaces-inside: 0
    max-spaces-inside: 0
...

I use it with this alias

alias yams='find . -type f -name "*.yml*" | sed "s|\./||g" | egrep -v "(\.kitchen/|\[warning\]|\.molecule/)" | xargs yamllint -f parsable'

@ferrarimarco
Copy link
Contributor Author

@pgporada thanks. I'll check yamllint!

@pgporada
Copy link

pgporada commented Feb 7, 2017

I hope it helps you! I like the feeling of linting my infrastructure code in any way possible. It's "new" and "different".

@ferrarimarco
Copy link
Contributor Author

@pgporada added in my PR 😄

@iknite
Copy link
Owner

iknite commented Feb 10, 2017

I was on vacations, I'll check it ASAP
Thanks!

@ferrarimarco
Copy link
Contributor Author

Hi @iknite any news? 👍

@iknite
Copy link
Owner

iknite commented Feb 13, 2017

I was reviewing it right now. :)

@iknite
Copy link
Owner

iknite commented Feb 13, 2017

I am worried about multiple use cases.

I am +1 to add a test environment, but not without a question in the cookiecutter (To allow simpler use cases outside galaxy), and also without travis (for private repositories).

I´m also in favour to BATS. So 3 levels of configuration and multiple choices. It´s something that requires a little more effort.

More on this soon, but for now thanks @ferrarimarco for bring this to the table, just let me be cautious.

@ferrarimarco
Copy link
Contributor Author

Ok, no prob.

Here is an overview (about Chef, but some concepts apply here also): https://blog.chef.io/2015/04/21/overview-of-test-driven-infrastructure-with-chef/

@ferrarimarco
Copy link
Contributor Author

By the way feel free to close that PR. After discussion I can open another one to help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants