Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puppet provisioner not detecting SSH connection default #23004

Closed
alexharv074 opened this issue Oct 4, 2019 · 1 comment
Closed

Puppet provisioner not detecting SSH connection default #23004

alexharv074 opened this issue Oct 4, 2019 · 1 comment

Comments

@alexharv074
Copy link
Contributor

@alexharv074 alexharv074 commented Oct 4, 2019

Terraform Version

▶ terraform -v 
Terraform v0.12.9
+ provider.aws v2.23.0

Terraform Configuration Files

Given code like this:

resource "aws_instance" "agent" {
  ami           = local.ami_id
  instance_type = "t2.micro"
  key_name      = "default"

  connection {
    host        = self.public_ip
    user        = "ec2-user"
    private_key = file("~/.ssh/default.pem")
    // Intent here is to use default type of "ssh"
  }

  provisioner "puppet" {
    use_sudo    = true
    server      = aws_instance.master.public_dns
    server_user = "ec2-user"
  }

  depends_on = [aws_instance.master]

Debug Output

When running terraform apply, Puppet Bolt fails in a confusing way:

aws_instance.agent: Still creating... [50s elapsed]                                                                                                                                       
aws_instance.agent: Still creating... [1m0s elapsed]                                                                                                                                      
                                                                                                                                                                                          
                                                                                                                                                                                          
Error: puppet_agent::install failed: Bolt: "bolt task run --nodes ://13.54.219.62 -u ec2-user --run-as root --no-host-key-check --format json --connect-timeout 120 puppet_agent::install"

Notice in this output that "ssh" is missing from --nodes ://13.54.219.62.

Followed by some JSON output. If I move the JSON into a file response.json then it contains:

{
  "items": [
    {
      "node": "://54.252.143.233",
      "target": "://54.252.143.233",
      "action": null,
      "object": null,
      "status": "failure",
      "result": {
        "_error": {
          "kind": "puppetlabs.tasks/exception-error",
          "issue_code": "EXCEPTION",
          "msg": "logger must have a name",
          "details": {
            "class": "ArgumentError",
            "stack_trace": "/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:149:in `initialize'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:56:in `new'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:56:in `block in []'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/utils.rb:162:in `block in synchronize'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/utils.rb:159:in `synchronize'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/utils.rb:159:in `synchronize'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:52:in `[]'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/ssh/connection.rb:31:in `initialize'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/ssh.rb:68:in `new'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/ssh.rb:68:in `with_connection'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/sudoable.rb:84:in `run_task'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/base.rb:129:in `block in batch_task'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/base.rb:71:in `with_events'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/base.rb:127:in `batch_task'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:264:in `block (3 levels) in run_task'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:225:in `with_node_logging'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:263:in `block (2 levels) in run_task'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:103:in `block (3 levels) in queue_execute'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'\\n/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'"
          }
        }
      }
    }
  ],
  "node_count": 1,
  "elapsed_time": 0
}

Then cleaning that up so I can read the Bolt stack trace:

▶ printf "$(jq -r '.items[].result._error.details.stack_trace' response.json)"
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:149:in `initialize'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:56:in `new'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:56:in `block in []'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/utils.rb:162:in `block in synchronize'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/utils.rb:159:in `synchronize'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/utils.rb:159:in `synchronize'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/logger.rb:52:in `[]'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/ssh/connection.rb:31:in `initialize'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/ssh.rb:68:in `new'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/ssh.rb:68:in `with_connection'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/sudoable.rb:84:in `run_task'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/base.rb:129:in `block in batch_task'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/base.rb:71:in `with_events'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/transport/base.rb:127:in `batch_task'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:264:in `block (3 levels) in run_task'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:225:in `with_node_logging'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:263:in `block (2 levels) in run_task'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/bolt-1.27.0/lib/bolt/executor.rb:103:in `block (3 levels) in queue_execute'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/concurrent-ruby-1.1.5/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'
/opt/puppetlabs/bolt/lib/ruby/gems/2.5.0/gems/logging-2.2.2/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'

Expected Behavior

Docs here suggest a connection block should default to type "ssh".

Actual Behavior

As above. The workaround is to specify the type = "ssh" in the connection block.

Additional Context

Tim Sharpe the author of the Puppet provisioner mentioned that he only ever tested using a connection that explicitly set type = "ssh". His test code is here.

More info

After going through both the Bolt & Terraform code it appears there are two issues:

1/ This bug.

2/ Bolt seems to have a bug and the logger is broken if if the SSH is missing from the nodes argument like --nodes ://13.54.219.62 instead of --nodes ssh://13.54.219.62.

alexharv074 added a commit to alexharv074/terraform-puppet-provisioner-test that referenced this issue Oct 5, 2019
alexharv074 added a commit to alexharv074/terraform that referenced this issue Oct 11, 2019
Before this, the Terraform Puppet provisioner would error out in a
confusing way if the type attribute in a connection block was not given.

Apparently an omitted type leads to type having a value "" which must be
then assumed to mean "ssh".
alexharv074 added a commit to alexharv074/terraform that referenced this issue Oct 12, 2019
Before this, the Terraform Puppet provisioner would error out in a
confusing way if the type attribute in a connection block was not given.

Apparently an omitted type leads to type having a value "" which must be
then assumed to mean "ssh".
@hashibot

This comment has been minimized.

Copy link

@hashibot hashibot bot commented Nov 17, 2019

I'm going to lock this issue because it has been closed for 30 days . This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashibot hashibot bot locked and limited conversation to collaborators Nov 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants
You can’t perform that action at this time.