ansible-wrapper 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee765d2b80572fec0da1ec9ddc043211872330ed9a6f40fc062cb72d65c02c50
4
- data.tar.gz: c849698d3def8e27a816ce340154aac9386b2f5d253e568d9560574472d250f9
3
+ metadata.gz: 502f430dd8b6fca43b1847722b1bdd51ae6a8df1eda0b8f2f035c93f6091ecc4
4
+ data.tar.gz: 48070b75f6cbcac9f1c90baa5371f7c651572699d342f219ba738ed2c011d3b8
5
5
  SHA512:
6
- metadata.gz: f1e61631280784a6a85d34593206abba2420d978e372a9b44d3fecfef48efdc16df50d603097dc2dfd9d11fcb4a92f31f836eed54fe0d77ee1006273522bdeb1
7
- data.tar.gz: a95a9ebaa9019a503011a318a9c28256f2d1613b6a384b6bc2114875db687561dd34be830f9fa49a3f14d48cf0e9750b2e77ce447a13e016cb0d6c6ecd4ef0de
6
+ metadata.gz: 5f7b489399ab99c55c69fa11793e8c24e0cf6860c6c4bdaf5637f2ba0540a2006ce395c96ad20d7f9334bbd4af32677fbf260a0cce5a2fb16c891724e62af52a
7
+ data.tar.gz: 7bb2ed85834fe9b2e4699e38c129c14739560e9a3a7aa7f4e65740f08fc8ebefeb0575c85a0b5ef0e585529f7432feae786aee2d7ef6fbbf6dffe419bff1c784
@@ -8,26 +8,62 @@ jobs:
8
8
  strategy:
9
9
  matrix:
10
10
  ansible:
11
- - 2.0.2
12
- - 2.1.6
13
- - 2.2.3
14
- - 2.3.3
15
- - 2.4.6
16
- - 2.5.15
17
- - 2.6.19
18
- - 2.7.12
19
11
  - 2.8.5
12
+ - 2.7.12
13
+ - 2.6.19
14
+ - 2.5.15
15
+ - 2.4.6
16
+ - 2.3.3
17
+ - 2.2.3
18
+ - 2.1.6
19
+ - 2.0.2
20
20
  steps:
21
21
  - uses: actions/checkout@v1
22
- - name: Run tests against Ruby 2.6.4
23
- run: RUBY_VERSION=2.6.4 ANSIBLE_VERSION=${{ matrix.ansible }} && docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && rake"
24
- - name: Run tests against Ruby 2.5.6
25
- run: RUBY_VERSION=2.5.6 ANSIBLE_VERSION=${{ matrix.ansible }} && docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && rake"
26
- - name: Run tests against Ruby 2.4.7
27
- run: RUBY_VERSION=2.4.7 ANSIBLE_VERSION=${{ matrix.ansible }} && docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && rake"
28
- - name: Run tests against Ruby 2.3.7
29
- run: RUBY_VERSION=2.3.7 ANSIBLE_VERSION=${{ matrix.ansible }} && docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && rake"
30
- - name: Run tests against Ruby 2.2.7
31
- run: RUBY_VERSION=2.2.7 ANSIBLE_VERSION=${{ matrix.ansible }} && docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && rake"
32
- - name: Run tests against Ruby 2.1.10
33
- run: RUBY_VERSION=2.1.10 ANSIBLE_VERSION=${{ matrix.ansible }} && docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && rake"
22
+ - name: Test against Ruby 2.6.4
23
+ env:
24
+ RUBY_VERSION: 2.6.4
25
+ ANSIBLE_VERSION: ${{ matrix.ansible }}
26
+ run: >
27
+ docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION
28
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 &&
29
+ COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} COVERALLS_RUN_LOCALLY=true bundle exec rake"
30
+
31
+ - name: Test against Ruby 2.5.6
32
+ env:
33
+ RUBY_VERSION: 2.5.6
34
+ ANSIBLE_VERSION: ${{ matrix.ansible }}
35
+ run: >
36
+ docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION
37
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
38
+
39
+ - name: Test against Ruby 2.4.7
40
+ env:
41
+ RUBY_VERSION: 2.4.7
42
+ ANSIBLE_VERSION: ${{ matrix.ansible }}
43
+ run: >
44
+ docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION
45
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
46
+
47
+ - name: Test against Ruby 2.3.7
48
+ env:
49
+ RUBY_VERSION: 2.3.7
50
+ ANSIBLE_VERSION: ${{ matrix.ansible }}
51
+ run: >
52
+ docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION
53
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
54
+
55
+ - name: Test against Ruby 2.2.7
56
+ env:
57
+ RUBY_VERSION: 2.2.7
58
+ ANSIBLE_VERSION: ${{ matrix.ansible }}
59
+ run: >
60
+ docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION
61
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
62
+
63
+ - name: Test against Ruby 2.1.10
64
+ env:
65
+ RUBY_VERSION: 2.1.10
66
+ ANSIBLE_VERSION: ${{ matrix.ansible }}
67
+ run: >
68
+ docker run --rm -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION
69
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
data/.travis.yml CHANGED
@@ -1,21 +1,33 @@
1
- language: minimal
1
+ language: bash
2
2
  services:
3
3
  - docker
4
4
  env:
5
- - ANSIBLE_VERSION=2.0.2
6
- - ANSIBLE_VERSION=2.1.6
7
- - ANSIBLE_VERSION=2.2.3
8
- - ANSIBLE_VERSION=2.3.3
9
- - ANSIBLE_VERSION=2.4.6
10
- - ANSIBLE_VERSION=2.5.15
11
- - ANSIBLE_VERSION=2.6.19
12
- - ANSIBLE_VERSION=2.7.12
13
5
  - ANSIBLE_VERSION=2.8.5
14
- - RUBY_VERSION=2.1.10
15
- - RUBY_VERSION=2.2.7
16
- - RUBY_VERSION=2.3.7
17
- - RUBY_VERSION=2.4.7
18
- - RUBY_VERSION=2.5.6
19
- - RUBY_VERSION=2.6.4
6
+ - ANSIBLE_VERSION=2.7.12
7
+ - ANSIBLE_VERSION=2.6.19
8
+ - ANSIBLE_VERSION=2.5.15
9
+ - ANSIBLE_VERSION=2.4.6
10
+ - ANSIBLE_VERSION=2.3.3
11
+ - ANSIBLE_VERSION=2.2.3
12
+ - ANSIBLE_VERSION=2.1.6
13
+ - ANSIBLE_VERSION=2.0.2
20
14
  script:
21
- - docker run --rm -it -v $PWD:/app pgeraghty/ansible-ruby:$RUBY_VERSION-$ANSIBLE_VERSION /bin/sh -c cd /app && bundle install --jobs=3 --retry=3 --deployment && rake
15
+ - >
16
+ RUBY=2.6.4 && docker run --rm -e TRAVIS -e TRAVIS_JOB_ID -e TRAVIS_BRANCH -e TRAVIS_PULL_REQUEST -it
17
+ -v $PWD:/app pgeraghty/ansible-ruby:$RUBY-$ANSIBLE_VERSION /bin/sh -c
18
+ "cd /app && bundle install --jobs=3 --retry=3 && CI=true bundle exec rake"
19
+ - >
20
+ RUBY=2.5.6 && docker run --rm -it -v $PWD:/app pgeraghty/ansible-ruby:$RUBY-$ANSIBLE_VERSION
21
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
22
+ - >
23
+ RUBY=2.4.7 && docker run --rm -it -v $PWD:/app pgeraghty/ansible-ruby:$RUBY-$ANSIBLE_VERSION
24
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
25
+ - >
26
+ RUBY=2.3.7 && docker run --rm -it -v $PWD:/app pgeraghty/ansible-ruby:$RUBY-$ANSIBLE_VERSION
27
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
28
+ - >
29
+ RUBY=2.2.7 && docker run --rm -it -v $PWD:/app pgeraghty/ansible-ruby:$RUBY-$ANSIBLE_VERSION
30
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
31
+ - >
32
+ RUBY=2.1.10 && docker run --rm -it -v $PWD:/app pgeraghty/ansible-ruby:$RUBY-$ANSIBLE_VERSION
33
+ /bin/sh -c "cd /app && bundle install --jobs=3 --retry=3 && bundle exec rake"
data/README.md CHANGED
@@ -43,15 +43,15 @@ Ansible::AdHoc.run 'all -m shell -a "echo Test" -i localhost,'
43
43
  ### Playbooks
44
44
 
45
45
  ```ruby
46
- Ansible::Playbook.run '-i localhost, spec/mock_playbook.yml'
46
+ Ansible::Playbook.run '-i localhost, spec/fixtures/mock_playbook.yml'
47
47
  ```
48
48
 
49
49
  ```ruby
50
- Ansible::Playbook.stream('-i localhost, spec/mock_playbook.yml') # defaults to standard output
50
+ Ansible::Playbook.stream('-i localhost, spec/fixtures/mock_playbook.yml') # defaults to standard output
51
51
  ```
52
52
 
53
53
  ```ruby
54
- Ansible::Playbook.stream('-i localhost, spec/mock_playbook.yml') { |line_of_output| puts line_of_output }
54
+ Ansible::Playbook.stream('-i localhost, spec/fixtures/mock_playbook.yml') { |line_of_output| puts line_of_output }
55
55
  ```
56
56
 
57
57
  ### Shortcuts
@@ -69,7 +69,7 @@ A['all -i localhost, --list-hosts'] # alias for Ansible::AdHoc.run
69
69
  ```
70
70
 
71
71
  ```ruby
72
- A << '-i localhost, spec/mock_playbook.yml' # alias for Ansible::Playbook.stream
72
+ A << '-i localhost, spec/fixtures/mock_playbook.yml' # alias for Ansible::Playbook.stream
73
73
  ```
74
74
 
75
75
  ## Coming Soon
@@ -27,6 +27,8 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
+ spec.add_dependency 'json'
31
+
30
32
  spec.add_development_dependency 'bundler','~> 1.10'
31
33
  spec.add_development_dependency 'rake', '~> 10.0'
32
34
  spec.add_development_dependency 'rspec'
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'ansible'
4
+ require 'ansible-wrapper'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")
@@ -63,7 +63,7 @@ get '/streaming' do
63
63
  #content_type 'text/plain'
64
64
  stream do |out|
65
65
  out << CONSOLE_OUTPUT_START
66
- Ansible.stream ['-i', 'localhost,', File.expand_path('../../../spec/mock_playbook.yml', __FILE__)]*' ' do |line|
66
+ Ansible.stream ['-i', 'localhost,', File.expand_path('../../../spec/fixtures/mock_playbook.yml', __FILE__)]*' ' do |line|
67
67
  Ansible::Output.to_html line, out
68
68
  end
69
69
  out << CONSOLE_OUTPUT_END
@@ -1,5 +1,4 @@
1
1
  require 'ansible/version'
2
- require 'ansible/config'
3
2
  require 'ansible/ad_hoc'
4
3
  require 'ansible/playbook'
5
4
  require 'ansible/output'
@@ -1,30 +1,36 @@
1
- module Ansible::Methods
2
- BIN = 'ansible'
1
+ require 'ansible/config'
2
+ require 'json'
3
3
 
4
- def one_off cmd
5
- `#{config.to_s "#{BIN} #{cmd}"}`
6
- end
7
- alias :[] :one_off
4
+ module Ansible
5
+ module Methods
6
+ BIN = 'ansible'
8
7
 
9
- # this solution should work for Ansible pre-2.0 as well as 2.0+
10
- def list_hosts cmd
11
- one_off("#{cmd} --list-hosts").scan(IP_OR_HOSTNAME).map { |ip| ip.first.strip }
12
- end
8
+ def one_off cmd
9
+ `#{config.to_s "#{BIN} #{cmd}"}`
10
+ end
11
+ alias :[] :one_off
13
12
 
14
- def parse_host_vars(host, inv_file, filter = 'hostvars[inventory_hostname]')
15
- hostvars_filter = filter
16
- cmd = "all -m debug -a 'var=#{hostvars_filter}' -i #{inv_file} -l #{host} --one-line"
17
- hostvars = JSON.parse(self[cmd].split(/>>|=>/).last)
13
+ def list_hosts cmd
14
+ output = one_off("#{cmd} --list-hosts").gsub!(/\s+hosts.*:\n/, '').strip
15
+ output.split("\n").map(&:strip)
16
+ end
18
17
 
19
- if Gem::Version.new(Ansible::Config::VERSION) >= Gem::Version.new('2.0')
20
- hostvars[hostvars_filter]
21
- else
22
- hostvars['var'][hostvars_filter]
18
+ def parse_host_vars(host, inv_file, filter = 'hostvars[inventory_hostname]')
19
+ cmd = "all -m debug -a 'var=#{filter}' -i #{inv_file} -l #{host}"
20
+ json = self[cmd].split(/>>|=>/).last
21
+
22
+ # remove any colour added to console output
23
+ # TODO move to Output module as #bleach, perhaps use term-ansicolor
24
+ # possibly replace regexp with /\e\[(?:(?:[349]|10)[0-7]|[0-9]|[34]8;5;\d{1,3})?m/
25
+ # possibly use ANSIBLE_NOCOLOR? or --nocolor
26
+ json = json.strip.chomp.gsub(/\e\[[0-1][;]?(3[0-7]|90|1)?m/, '')
27
+
28
+ hostvars = JSON.parse(json)
29
+
30
+ hostvars[filter]
23
31
  end
24
32
  end
25
- end
26
33
 
27
- module Ansible
28
34
  module AdHoc
29
35
  include Ansible::Config
30
36
  include Ansible::Methods
@@ -1,53 +1,55 @@
1
- module Ansible::Config
2
- PATH = 'lib/ansible/'
3
- IP_OR_HOSTNAME = /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})$|^((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]))/
4
- SKIP_HOSTVARS = %w(ansible_version inventory_dir inventory_file inventory_hostname inventory_hostname_short group_names groups omit playbook_dir)
5
- VERSION = `ansible --version`.split("\n").first.split.last rescue nil # nil when Ansible not installed
6
-
7
- DefaultConfig = Struct.new(:env, :extra_vars, :params) do
8
- def initialize
9
- self.env = {
10
- 'ANSIBLE_FORCE_COLOR' => 'True',
11
- 'ANSIBLE_HOST_KEY_CHECKING' => 'False'
12
- }
13
-
14
- self.params = {
15
- debug: false
16
- }
17
-
18
- # options
19
- self.extra_vars = {
20
- # skip creation of .retry files
21
- 'retry_files_enabled' => 'False'
22
- }
23
- # TODO support --ssh-common-args, --ssh-extra-args
24
- # e.g. ansible-playbook --ssh-common-args="-o ServerAliveInterval=60" -i inventory install.yml
1
+ module Ansible
2
+ module Config
3
+ PATH = 'lib/ansible/'
4
+ # IP_OR_HOSTNAME = /((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})$|^((([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]))\n/
5
+ SKIP_HOSTVARS = %w(ansible_version inventory_dir inventory_file inventory_hostname inventory_hostname_short group_names groups omit playbook_dir)
6
+ VERSION = `ansible --version`.split("\n").first.split.last rescue nil # nil when Ansible not installed
7
+
8
+ DefaultConfig = Struct.new(:env, :extra_vars, :params) do
9
+ def initialize
10
+ self.env = {
11
+ 'ANSIBLE_FORCE_COLOR' => 'True',
12
+ 'ANSIBLE_HOST_KEY_CHECKING' => 'False'
13
+ }
14
+
15
+ self.params = {
16
+ debug: false
17
+ }
18
+
19
+ # options
20
+ self.extra_vars = {
21
+ # skip creation of .retry files
22
+ 'retry_files_enabled' => 'False'
23
+ }
24
+ # TODO support --ssh-common-args, --ssh-extra-args
25
+ # e.g. ansible-playbook --ssh-common-args="-o ServerAliveInterval=60" -i inventory install.yml
26
+ end
27
+
28
+ # NB: --extra-vars can also accept JSON string, see http://stackoverflow.com/questions/25617273/pass-array-in-extra-vars-ansible
29
+ def options
30
+ x = extra_vars.each_with_object('--extra-vars=\'') { |kv, a| a << "#{kv.first}=\"#{kv.last}\" " }.strip+'\'' if extra_vars unless extra_vars.empty?
31
+ # can test with configure { |config| config.extra_vars.clear }
32
+
33
+ [x, '--ssh-extra-args=\'-o UserKnownHostsFile=/dev/null\'']*' '
34
+ end
35
+
36
+ def to_s(cmd)
37
+ entire_cmd = [env.each_with_object([]) { |kv, a| a << kv*'=' } * ' ', cmd, options]*' '
38
+ puts entire_cmd if params[:debug]
39
+ entire_cmd
40
+ end
25
41
  end
26
42
 
27
- # NB: --extra-vars can also accept JSON string, see http://stackoverflow.com/questions/25617273/pass-array-in-extra-vars-ansible
28
- def options
29
- x = extra_vars.each_with_object('--extra-vars=\'') { |kv, a| a << "#{kv.first}=\"#{kv.last}\" " }.strip+'\'' if extra_vars unless extra_vars.empty?
30
- # can test with configure { |config| config.extra_vars.clear }
43
+ def configure
44
+ @config ||= DefaultConfig.new
45
+ yield(@config) if block_given?
31
46
 
32
- [x, '--ssh-extra-args=\'-o UserKnownHostsFile=/dev/null\'']*' '
47
+ # allow chaining if block given
48
+ block_given? ? self : @config
33
49
  end
34
50
 
35
- def to_s(cmd)
36
- entire_cmd = [env.each_with_object([]) { |kv, a| a << kv*'=' } * ' ', cmd, options]*' '
37
- puts entire_cmd if params[:debug]
38
- entire_cmd
51
+ def config
52
+ @config || configure
39
53
  end
40
54
  end
41
-
42
- def configure
43
- @config ||= DefaultConfig.new
44
- yield(@config) if block_given?
45
-
46
- # allow chaining if block given
47
- block_given? ? self : @config
48
- end
49
-
50
- def config
51
- @config || configure
52
- end
53
55
  end
@@ -1,47 +1,50 @@
1
1
  require 'strscan'
2
2
  require 'erb'
3
3
 
4
- module Ansible::Output
5
- COLOR = {
6
- '1' => 'font-weight: bold',
7
- '30' => 'color: black',
8
- '31' => 'color: red',
9
- '32' => 'color: green',
10
- '33' => 'color: yellow',
11
- '34' => 'color: blue',
12
- '35' => 'color: magenta',
13
- '36' => 'color: cyan',
14
- '37' => 'color: white',
15
- '90' => 'color: grey'
16
- }
4
+ module Ansible
5
+ module Output
6
+ COLOR = {
7
+ '1' => 'font-weight: bold',
8
+ '30' => 'color: black',
9
+ '31' => 'color: red',
10
+ '32' => 'color: green',
11
+ '33' => 'color: yellow',
12
+ '34' => 'color: blue',
13
+ '35' => 'color: magenta',
14
+ '36' => 'color: cyan',
15
+ '37' => 'color: white',
16
+ '90' => 'color: grey'
17
+ }
17
18
 
18
- def self.to_html(line, stream='')
19
- s = StringScanner.new(ERB::Util.h line)
20
- while(!s.eos?)
21
- if s.scan(/\e\[([0-1]);(3[0-7]|90|1)m/)
22
- bold, colour = s.captures
23
- styles = []
19
+ def self.to_html(line, stream='')
20
+ s = StringScanner.new(ERB::Util.h line)
21
+ while(!s.eos?)
22
+ if s.scan(/\e\[([0-1])?[;]?(3[0-7]|90|1)m/)
23
+ bold, colour = s[1], s[2]
24
+ styles = []
24
25
 
25
- styles << COLOR[bold] if bold.to_i == 1
26
- styles << COLOR[colour]
26
+ styles << COLOR[bold] if bold.to_i == 1
27
+ styles << COLOR[colour]
27
28
 
28
- span =
29
- if styles.empty?
30
- %{<span>}
31
- else
32
- %{<span style="#{styles*'; '};">}
33
- end
29
+ span =
30
+ # in case of invalid colours, although this may be impossible
31
+ if styles.compact.empty?
32
+ %{<span>}
33
+ else
34
+ %{<span style="#{styles*'; '};">}
35
+ end
34
36
 
35
- stream << span
36
- else
37
- if s.scan(/\e\[0m/)
37
+ stream << span
38
+ elsif s.scan(/\e\[0m/)
38
39
  stream << %{</span>}
40
+ elsif s.scan(/\e\[[^0]*m/)
41
+ stream << '<span>'
39
42
  else
40
43
  stream << s.scan(/./m)
41
44
  end
42
45
  end
43
- end
44
46
 
45
- stream
47
+ stream
48
+ end
46
49
  end
47
50
  end
@@ -1,3 +1,4 @@
1
+ require 'ansible/config'
1
2
  require 'ansible/safe_pty'
2
3
 
3
4
  module Ansible
@@ -1,3 +1,3 @@
1
1
  module Ansible
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Geraghty
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2019-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -96,9 +110,9 @@ files:
96
110
  - LICENSE.txt
97
111
  - README.md
98
112
  - Rakefile
99
- - ansible-wrapper-0.1.2.gem
100
113
  - ansible-wrapper.gemspec
101
114
  - bin/console
115
+ - bin/rake
102
116
  - bin/setup
103
117
  - examples/streaming/Gemfile
104
118
  - examples/streaming/Gemfile.lock
Binary file