-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak new functionality, augment tests
- Loading branch information
Showing
15 changed files
with
240 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
module Ansible::Config | ||
PATH = 'lib/ansible/' | ||
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]))/ | ||
SKIP_HOSTVARS = %w(ansible_version inventory_dir inventory_file inventory_hostname inventory_hostname_short group_names groups omit playbook_dir) | ||
VERSION = `ansible --version`.split("\n").first.split.last rescue nil # nil when Ansible not installed | ||
|
||
DefaultConfig = Struct.new(:env, :extra_vars, :params) do | ||
def initialize | ||
self.env = { | ||
'ANSIBLE_FORCE_COLOR' => 'True', | ||
'ANSIBLE_HOST_KEY_CHECKING' => 'False' | ||
} | ||
|
||
self.params = { | ||
debug: false | ||
} | ||
|
||
# options | ||
self.extra_vars = { | ||
# skip creation of .retry files | ||
'retry_files_enabled' => 'False' | ||
} | ||
# TODO support --ssh-common-args, --ssh-extra-args | ||
# e.g. ansible-playbook --ssh-common-args="-o ServerAliveInterval=60" -i inventory install.yml | ||
module Ansible | ||
module Config | ||
PATH = 'lib/ansible/' | ||
# 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/ | ||
SKIP_HOSTVARS = %w(ansible_version inventory_dir inventory_file inventory_hostname inventory_hostname_short group_names groups omit playbook_dir) | ||
VERSION = `ansible --version`.split("\n").first.split.last rescue nil # nil when Ansible not installed | ||
|
||
DefaultConfig = Struct.new(:env, :extra_vars, :params) do | ||
def initialize | ||
self.env = { | ||
'ANSIBLE_FORCE_COLOR' => 'True', | ||
'ANSIBLE_HOST_KEY_CHECKING' => 'False' | ||
} | ||
|
||
self.params = { | ||
debug: false | ||
} | ||
|
||
# options | ||
self.extra_vars = { | ||
# skip creation of .retry files | ||
'retry_files_enabled' => 'False' | ||
} | ||
# TODO support --ssh-common-args, --ssh-extra-args | ||
# e.g. ansible-playbook --ssh-common-args="-o ServerAliveInterval=60" -i inventory install.yml | ||
end | ||
|
||
# NB: --extra-vars can also accept JSON string, see http://stackoverflow.com/questions/25617273/pass-array-in-extra-vars-ansible | ||
def options | ||
x = extra_vars.each_with_object('--extra-vars=\'') { |kv, a| a << "#{kv.first}=\"#{kv.last}\" " }.strip+'\'' if extra_vars unless extra_vars.empty? | ||
# can test with configure { |config| config.extra_vars.clear } | ||
|
||
[x, '--ssh-extra-args=\'-o UserKnownHostsFile=/dev/null\'']*' ' | ||
end | ||
|
||
def to_s(cmd) | ||
entire_cmd = [env.each_with_object([]) { |kv, a| a << kv*'=' } * ' ', cmd, options]*' ' | ||
puts entire_cmd if params[:debug] | ||
entire_cmd | ||
end | ||
end | ||
|
||
# NB: --extra-vars can also accept JSON string, see http://stackoverflow.com/questions/25617273/pass-array-in-extra-vars-ansible | ||
def options | ||
x = extra_vars.each_with_object('--extra-vars=\'') { |kv, a| a << "#{kv.first}=\"#{kv.last}\" " }.strip+'\'' if extra_vars unless extra_vars.empty? | ||
# can test with configure { |config| config.extra_vars.clear } | ||
def configure | ||
@config ||= DefaultConfig.new | ||
yield(@config) if block_given? | ||
|
||
[x, '--ssh-extra-args=\'-o UserKnownHostsFile=/dev/null\'']*' ' | ||
# allow chaining if block given | ||
block_given? ? self : @config | ||
end | ||
|
||
def to_s(cmd) | ||
entire_cmd = [env.each_with_object([]) { |kv, a| a << kv*'=' } * ' ', cmd, options]*' ' | ||
puts entire_cmd if params[:debug] | ||
entire_cmd | ||
def config | ||
@config || configure | ||
end | ||
end | ||
|
||
def configure | ||
@config ||= DefaultConfig.new | ||
yield(@config) if block_given? | ||
|
||
# allow chaining if block given | ||
block_given? ? self : @config | ||
end | ||
|
||
def config | ||
@config || configure | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,50 @@ | ||
require 'strscan' | ||
require 'erb' | ||
|
||
module Ansible::Output | ||
COLOR = { | ||
'1' => 'font-weight: bold', | ||
'30' => 'color: black', | ||
'31' => 'color: red', | ||
'32' => 'color: green', | ||
'33' => 'color: yellow', | ||
'34' => 'color: blue', | ||
'35' => 'color: magenta', | ||
'36' => 'color: cyan', | ||
'37' => 'color: white', | ||
'90' => 'color: grey' | ||
} | ||
module Ansible | ||
module Output | ||
COLOR = { | ||
'1' => 'font-weight: bold', | ||
'30' => 'color: black', | ||
'31' => 'color: red', | ||
'32' => 'color: green', | ||
'33' => 'color: yellow', | ||
'34' => 'color: blue', | ||
'35' => 'color: magenta', | ||
'36' => 'color: cyan', | ||
'37' => 'color: white', | ||
'90' => 'color: grey' | ||
} | ||
|
||
def self.to_html(line, stream='') | ||
s = StringScanner.new(ERB::Util.h line) | ||
while(!s.eos?) | ||
if s.scan(/\e\[([0-1]);(3[0-7]|90|1)m/) | ||
bold, colour = s.captures | ||
styles = [] | ||
def self.to_html(line, stream='') | ||
s = StringScanner.new(ERB::Util.h line) | ||
while(!s.eos?) | ||
if s.scan(/\e\[([0-1])?[;]?(3[0-7]|90|1)m/) | ||
bold, colour = s.captures | ||
styles = [] | ||
|
||
styles << COLOR[bold] if bold.to_i == 1 | ||
styles << COLOR[colour] | ||
styles << COLOR[bold] if bold.to_i == 1 | ||
styles << COLOR[colour] | ||
|
||
span = | ||
if styles.empty? | ||
%{<span>} | ||
else | ||
%{<span style="#{styles*'; '};">} | ||
end | ||
span = | ||
# in case of invalid colours, although this may be impossible | ||
if styles.compact.empty? | ||
%{<span>} | ||
else | ||
%{<span style="#{styles*'; '};">} | ||
end | ||
|
||
stream << span | ||
else | ||
if s.scan(/\e\[0m/) | ||
stream << span | ||
elsif s.scan(/\e\[0m/) | ||
stream << %{</span>} | ||
elsif s.scan(/\e\[[^0]*m/) | ||
stream << '<span>' | ||
else | ||
stream << s.scan(/./m) | ||
end | ||
end | ||
end | ||
|
||
stream | ||
stream | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
require 'ansible/config' | ||
require 'ansible/safe_pty' | ||
|
||
module Ansible | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.