Connection fails where dynamic inventory has basic host list
temyers opened this issue · 19 comments
I'm using the ec2.py dynamic inventory which creates the following ansible_spec properties from AnsibleSpec.get_properties
{"name"=>"deploy-webserver", "hosts"=>["1.2.3.4"], "user"=>"ec2-user", "sudo"=>true, "roles"=>["webserver"]}
using the generated Rakefile from ansiblespec-init, the ENV['TARGET_HOST']
and ENV['TARGET_PORT']
are not set correctly (both empty) since hosts contains a simple string.
What is basic host list
?
Would you show me result that execute python ec2.py --list
?
(I don't have ec2 environment now...)
I assume that basic host list
is below json text.
{"webservers": [ "host2.example.com", "host3.example.com" ]}
Please let me know what your think.
Hi,
Sorry for the late reply.
Yeah my "basic host list" is a the simple string list of items (wither host names or IP addresses).
My example above AnsibleSpec.get_properties
returned (IPs redacted):
{"name"=>"deploy-webserver", "hosts"=>["1.2.3.4"], "user"=>"ec2-user", "sudo"=>true, "roles"=>["webserver"]}
be using puts properties
into the RakeFile.
I'll post my ec2.py --list also
I created this branch.
This branch set ssh port and hostname when simple strings.
Could you try using this branch?
Sorry for taking so long to post this.
Here's a (redacted & trimmed) snippet from my ec2.py --list
:
{
"_meta": {
"hostvars": {
"54.1.2.3": {
"ec2_ip_address": "54.1.2.3",
"ec2_key_name": “my-secret-key",
"ec2_launch_time": "2016-01-06T03:59:56.000Z",
"ec2_tag_Name": "sample-app",
"ec2_tag_Stack": "sample-app”
// other entries omitted
}
}
},
"tag_Name_sample_app": [
"54.1.2.3"
]
// other entries omitted
}
Thankyou!
I will check it!
I released 0.2.7.beta that use branch - Issue55_FailDynamicInventory
Please test it.
If you say okay, I will release v0.2.7
Thanks. I'll test and update.
Sorry for taking so long to respond to this.
Thanks for the update.
I get a failure when running against v0.2.6. The same tests/inventory running against 0.2.7.beta works.
Thanks!
Here's the commands I ran:
cd ansible_spec/
git checkout v0.2.7.beta
bundle install --binstubs=./bundler_stubs
export PATH="~/ansible_spec/bundler_stubs:$PATH"
mkdir -p ~/ansiblespec_test
cd ~/ansiblespec_test
ansiblespec-init
vi .ansiblespec
vi Rakefile
mkdir -p roles/webserver/spec
vi roles/webserver/spec/sample_spec.rb
rake serverspec:"configure and deploy the webservers"
where:
.ansiblespec:
---
-
playbook: site.yml
inventory: ../ansible/inventory/ec2.py
and sample_spec.rb:
require 'spec_helper'
describe 'something' do
describe user('ubuntu') do
it{ should exist }
end
end
and site.yml:
---
- name: configure and deploy the webservers
hosts: tag_Name_sample_webserver
user: ubuntu
sudo: yes
roles:
- webserver
0.2.7.beta rake output:
Run serverspec for configure and deploy the webservers to {"uri"=>"x.x.x.x", "port"=>22}
/home/vagrant/.rvm/rubies/ruby-2.2.3/bin/ruby -I/home/vagrant/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib:/home/vagrant/.rvm/gems/ruby-2.2.3/gems/rspec-support-3.4.1/lib /home/vagrant/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/exe/rspec --pattern roles/\{webserver\}/spec/\*_spec.rb
.
Finished in 2.35 seconds (files took 0.25354 seconds to load)
1 example, 0 failures
0.2.6 output:
Run serverspec for configure and deploy the webservers to x.x.x.x
/home/vagrant/.rvm/rubies/ruby-2.2.3/bin/ruby -I/home/vagrant/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/lib:/home/vagrant/.rvm/gems/ruby-2.2.3/gems/rspec-support-3.4.1/lib /home/vagrant/.rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.1/exe/rspec --pattern roles/\{webserver\}/spec/\*_spec.rb
F
Failures:
1) something User "ubuntu" should exist
Failure/Error: it{ should exist }
Errno::ECONNREFUSED:
Connection refused - connect(2) for 127.0.0.1
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/net-ssh-3.0.2/lib/net/ssh/transport/session.rb:70:in `initialize'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/net-ssh-3.0.2/lib/net/ssh.rb:225:in `new'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/net-ssh-3.0.2/lib/net/ssh.rb:225:in `start'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/backend/ssh.rb:76:in `create_ssh'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/backend/ssh.rb:110:in `ssh_exec!'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/backend/ssh.rb:17:in `block in run_command'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/backend/ssh.rb:67:in `with_env'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/backend/ssh.rb:16:in `run_command'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/helper/detect_os.rb:13:in `run_command'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/helper/detect_os/solaris.rb:3:in `detect'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/helper/detect_os.rb:5:in `detect'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/helper/os.rb:24:in `block in detect_os'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/helper/os.rb:23:in `each'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/helper/os.rb:23:in `detect_os'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/helper/os.rb:9:in `os'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/specinfra-2.49.0/lib/specinfra/runner.rb:7:in `method_missing'
# /home/vagrant/.rvm/gems/ruby-2.2.3/gems/serverspec-2.29.0/lib/serverspec/type/user.rb:4:in `exists?'
# ./roles/webserver/spec/sample_spec.rb:5:in `block (3 levels) in <top (required)>'
Finished in 0.01193 seconds (files took 0.217 seconds to load)
1 example, 1 failure
There are a couple of interesting points to note though:
- The 0.2.7.beta version doesn't output the spec.
- The error message seems to relate to a connection issue (different from my original error).
These may be down to a misconfiguration on my part.
Thanks
Thank you for testing of 0.2.7.beta.
- I think that
0.2.7.beta rake output:
looks good.What does"The 0.2.7.beta version doesn't output the spec."
mean? - it looks network error during access to your test machine.
"doesn't output the spec"
When the test runs, I'd expect that the output of the rake test to contain the specification (and the notification that it passed):
something
User "ubuntu"
should exist
But it doesn't. Any idea why this would be the case?
2) it looks network error during access to your test machine.
This was the original error I was getting (I was mistaken). The parsing isn't happening properly, resulting in the failure. If I re-apply my fix to the Rakefile in #56, then the 0.2.6 works as expected.
When I fix it so the 0.2.6 version works, I get the same output as 0.2.7.beta. So it must be an error in my config why the spec isn't being printed as expected.
So I'd say this is fixed.
oops, I'll wait until it's merged :)
I released v0.2.7
Awesome, thanks.
I'll update.
Great project!
- I think, Please add line
--format documentation
to your./rspec
.
#/.rspec
--format documentation