ansible-wrapper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 270d5a0826dc96740d79e0cd76daf3ef4ab5e674
4
+ data.tar.gz: 697b80e8a2faf62e52f0b54aa94f6520e0982935
5
+ SHA512:
6
+ metadata.gz: ab098f08b4224eedb21016ed6e7173452a58c252127f0ea358f93ca56c451e00fdc82da745644f2a8ad394ba6b5b997a74eb860f3b6a74bf09e1b26b2dcc9b97
7
+ data.tar.gz: f5d847fa3c0ee2c6c231abed3caa287097e593946094f6f6c282979dc29390e53cb4a4e0c57656f69a1544e085e0f4014f1660889997f6bdefa0f5cf23102b3d
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ .ruby-gemset
12
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+
5
+ before_install:
6
+ # make sure everything's up to date
7
+ - sudo apt-get update -qq
8
+ # install Python
9
+ - sudo apt-get install python
10
+ # upgrade pip
11
+ - sudo pip install --upgrade pip
12
+ # install Ansible
13
+ - sudo pip install ansible
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ansible-wrapper.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Paul Geraghty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,88 @@
1
+ # Ansible Wrapper
2
+
3
+ [![Build Status](https://travis-ci.org/pgeraghty/ansible-wrapper-ruby.svg?branch=master)](https://travis-ci.org/pgeraghty/ansible-wrapper-ruby)
4
+ [![Coverage Status](https://coveralls.io/repos/pgeraghty/ansible-wrapper-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/pgeraghty/ansible-wrapper-ruby?branch=master)
5
+
6
+ #### A lightweight Ruby wrapper around Ansible that allows for ad-hoc commands and playbook execution. The primary purpose is to support easy streaming output.
7
+
8
+ ## Installation
9
+
10
+ Ensure [Ansible](http://docs.ansible.com/intro_getting_started.html) is installed and available to shell commands i.e. in PATH.
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ansible-wrapper'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ansible-wrapper
25
+
26
+ ## Usage
27
+
28
+ ### Ad-hoc commands
29
+
30
+ ```ruby
31
+ Ansible::AdHoc.run 'all -i localhost, --list-hosts'
32
+ ```
33
+
34
+ ```ruby
35
+ Ansible::AdHoc.run 'all -m shell -a "echo Test" -i localhost,'
36
+ ```
37
+
38
+ ### Playbooks
39
+
40
+ ```ruby
41
+ Ansible::Playbook.run '-i localhost, spec/mock_playbook.yml'
42
+ ```
43
+
44
+ ```ruby
45
+ Ansible::Playbook.stream('-i localhost, spec/mock_playbook.yml') # defaults to standard output
46
+ ```
47
+
48
+ ```ruby
49
+ Ansible::Playbook.stream('-i localhost, spec/mock_playbook.yml') { |line_of_output| puts line_of_output }
50
+ ```
51
+
52
+ ### Shortcuts
53
+
54
+ To enable shortcuts:
55
+
56
+ ```ruby
57
+ Ansible.enable_shortcuts!
58
+ ```
59
+
60
+ You can then access Ansible via the `A` alias and use the following syntax:
61
+
62
+ ```ruby
63
+ A['all -i localhost, --list-hosts'] # alias for Ansible::AdHoc.run
64
+ ```
65
+
66
+ ```ruby
67
+ A << '-i localhost, spec/mock_playbook.yml' # alias for Ansible::Playbook.stream
68
+ ```
69
+
70
+ ## Coming Soon
71
+
72
+ * Streaming output example using Sinatra
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ansible-wrapper.
83
+
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
88
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ansible/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ansible-wrapper'
8
+ spec.version = Ansible::VERSION
9
+ spec.authors = ['Paul Geraghty']
10
+ spec.email = ['muse@appsthatcould.be']
11
+
12
+ spec.summary = %q{Ruby wrapper around Ansible}
13
+ spec.description = %q{A lightweight Ruby wrapper around Ansible that allows for ad-hoc commands and playbook execution.}
14
+ spec.homepage = 'https://github.com/pgeraghty/ansible-wrapper-ruby'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler','~> 1.10'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec'
33
+ spec.add_development_dependency 'coveralls'
34
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ansible'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ require 'ansible/version'
2
+ require 'ansible/ad_hoc'
3
+ require 'ansible/playbook'
4
+
5
+ module Ansible
6
+ extend self
7
+ ENV = {}
8
+
9
+ def env_string
10
+ ENV.map { |a| a*'=' }*' '
11
+ end
12
+
13
+ def enable_shortcuts!
14
+ require 'ansible/shortcuts'
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Ansible
2
+ module AdHoc
3
+ extend self
4
+ BIN = 'ansible'
5
+
6
+ def run(cmd, opts={})
7
+ cmd_line = [Ansible.env_string, BIN, cmd]*' '
8
+ `#{cmd_line}`
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ require 'ansible/safe_pty'
2
+
3
+ module Ansible
4
+ module Playbook
5
+ BIN = 'ansible-playbook'
6
+ extend self
7
+
8
+ def run(cmd, opts={})
9
+ cmd_line = [Ansible.env_string, 'ANSIBLE_FORCE_COLOR=True', BIN, cmd]*' '
10
+
11
+ `#{cmd_line}`
12
+ end
13
+
14
+ # This method uses PTY because otherwise output is buffered
15
+ def stream(cmd, opts={}, &block)
16
+ cmd_line = [Ansible.env_string, 'ANSIBLE_FORCE_COLOR=True', BIN, cmd]*' '
17
+
18
+ SafePty.spawn(cmd_line) do |r,w,p|
19
+ block_given? ? yield(r.gets) : puts(r.gets) until r.eof?
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ require 'pty'
2
+
3
+ module SafePty
4
+ def self.spawn command, &block
5
+
6
+ PTY.spawn(command) do |r,w,p|
7
+ begin
8
+ yield r,w,p
9
+ rescue Errno::EIO
10
+ # ignore Errno::EIO: Input/output error @ io_fillbuf
11
+ ensure
12
+ Process.wait p
13
+ end
14
+ end
15
+
16
+ $?.exitstatus
17
+ end
18
+ end
@@ -0,0 +1,12 @@
1
+ module Ansible
2
+ extend self
3
+
4
+ def [](cmd)
5
+ AdHoc.run cmd
6
+ end
7
+
8
+ def <<(cmd)
9
+ Playbook.stream cmd
10
+ end
11
+ end
12
+ A = Ansible unless defined?(A)
@@ -0,0 +1,3 @@
1
+ module Ansible
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansible-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Geraghty
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A lightweight Ruby wrapper around Ansible that allows for ad-hoc commands
70
+ and playbook execution.
71
+ email:
72
+ - muse@appsthatcould.be
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - ansible-wrapper.gemspec
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/ansible.rb
88
+ - lib/ansible/ad_hoc.rb
89
+ - lib/ansible/playbook.rb
90
+ - lib/ansible/safe_pty.rb
91
+ - lib/ansible/shortcuts.rb
92
+ - lib/ansible/version.rb
93
+ homepage: https://github.com/pgeraghty/ansible-wrapper-ruby
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Ruby wrapper around Ansible
117
+ test_files: []