Module: Ansible::Methods
Constant Summary collapse
- BIN =
'ansible'
Instance Method Summary collapse
-
#list_hosts(cmd) ⇒ Object
this solution should work for Ansible pre-2.0 as well as 2.0+.
- #one_off(cmd) ⇒ Object (also: #[])
- #parse_host_vars(host, inv_file, filter = 'hostvars[inventory_hostname]') ⇒ Object
Instance Method Details
#list_hosts(cmd) ⇒ Object
this solution should work for Ansible pre-2.0 as well as 2.0+
10 11 12 |
# File 'lib/ansible/ad_hoc.rb', line 10 def list_hosts cmd one_off("#{cmd} --list-hosts").scan(IP_OR_HOSTNAME).map { |ip| ip.first.strip } end |
#one_off(cmd) ⇒ Object Also known as: []
4 5 6 |
# File 'lib/ansible/ad_hoc.rb', line 4 def one_off cmd `#{config.to_s "#{BIN} #{cmd}"}` end |
#parse_host_vars(host, inv_file, filter = 'hostvars[inventory_hostname]') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ansible/ad_hoc.rb', line 14 def parse_host_vars(host, inv_file, filter = 'hostvars[inventory_hostname]') hostvars_filter = filter cmd = "all -m debug -a 'var=#{hostvars_filter}' -i #{inv_file} -l #{host} --one-line" hostvars = JSON.parse(self[cmd].split(/>>|=>/).last) if Gem::Version.new(Ansible::Config::VERSION) >= Gem::Version.new('2.0') hostvars[hostvars_filter] else hostvars['var'][hostvars_filter] end end |