Giter VIP home page Giter VIP logo

ec2-tags-ohai-plugin's People

Contributors

kierranm avatar mattlqx avatar tpath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ec2-tags-ohai-plugin's Issues

client var overrides Chef::Client in Chef Automate delivery-cmd

This is a really odd specific case, but I'll do my best to explain it. I run the ec2-tags-ohai-plugin on my hosts. I run Chef Automate which has "runner" processes that run on hosts and do the work for Workflow to build and deploy applications. The runners are installed by the main cli utility automate-ctl. Among other things, it installs ChefDK on to the node with a desired version and a delivery-cmd script that handles getting instructions from the main Chef Automate server.

delivery-cmd contains the following code near the top of the main block:

Chef::Config.from_file(Chef::Config.platform_specific_path("/etc/chef/client.rb"))
client = Chef::Client.new
client.run_ohai
client.node_name

When running with ChefDK 1.4.3, everything works as expected. But with ChefDK 1.5.0 and higher, running it yields this:

/usr/local/bin/delivery-cmd:103:in `<main>': undefined method `node_name' for #<Aws::EC2::Client> (NoMethodError)

Which instantly led me to look at this plugin because the prior line is client.run_ohai. I put a pry breakpoint in /etc/chef/ohai/plugins/ec2-tags.rb and after some debugging, it seems that with 1.4.3 the ec2-tags-ohai-plugin isn't loaded, but with 1.5.0 it is and that's where things get weird. When the ohai plugin is loaded, apparently a local variable client already exists in the plugin's scope and it's an instance of Chef::Client. When the ec2-tags-ohai-plugin is executed, the client variable is overridden with an instance of Aws::EC2::Client which persists after the plugin execution is complete in the main scope of the script and causes it to fail.

Here's some debugger output:

#  /usr/local/bin/delivery-cmd 

Frame number: 0/11

From: /etc/chef/ohai/plugins/ec2-tags.rb @ line 14 :

     9:   collect_data do
    10:     begin
    11:       require 'aws-sdk-core'
    12:       binding.pry
    13: 
 => 14:       client = Aws::EC2::Client.new region: ec2['placement_availability_zone'][0...-1]
    15:       resp = client.describe_tags(
    16:         filters: [
    17:           {
    18:             name: 'resource-id',
    19:             values: [

[1] pry(#<Ohai::NamedPlugin::EC2Tags>)> ls
Ohai::Mixin::Command#methods: run_command_backend  run_command_unix  run_command_windows
Ohai::Mixin::SecondsToHuman#methods: seconds_to_human
Ohai::Util::FileHelper#methods: which
Ohai::DSL::Plugin#methods: []  []=  attribute?  data  each  from  from_with_regex  get_attribute  has_key?  has_run?  hint?  method_missing  reset!  run  safe_run  set  set_attribute
Ohai::DSL::Plugin::VersionVII#methods: configuration  dependencies  name  provides  require_plugin  run_plugin  source  version
instance variables: @data  @has_run  @source  @version
locals: 
  _   _dir_  _file_  _out_  builder_auth_headers  chef_stacktrace_file  client  command_line     custom_cert_filepath  elapsed_time  http_proxy   job_data  path             raw_json  rest    start_datetime  workspace_bin 
  __  _ex_   _in_    _pry_  change_file           cli_env               cmd     compliance_json  e                     end_datetime  https_proxy  no_proxy  path_compliance  resp      server  streamy         workspace_root
[2] pry(#<Ohai::NamedPlugin::EC2Tags>)> client
=> #<Chef::Client:0x0000000324d620 ...>
[4] pry(#<Ohai::NamedPlugin::EC2Tags>)> next

From: /etc/chef/ohai/plugins/ec2-tags.rb @ line 15 :

    10:     begin
    11:       require 'aws-sdk-core'
    12:       binding.pry
    13: 
    14:       client = Aws::EC2::Client.new region: ec2['placement_availability_zone'][0...-1]
 => 15:       resp = client.describe_tags(
    16:         filters: [
    17:           {
    18:             name: 'resource-id',
    19:             values: [
    20:               ec2['instance_id']

[4] pry(#<Ohai::NamedPlugin::EC2Tags>):1> client
=> #<Aws::EC2::Client>

The quick workaround is to just rename the client variable in the plugin to something that doesn't collide like ec2_client and I'll submit a pull request for that. I'm not really sure where the problem is exactly upstream to report that. Any thoughts are appreciated.

['ec2']['tags'] is nil, any help?

Hey, currently using the latest version of this recipe. Currently using it against a base AWS Windows Server 2016 instance. It's currently unable to find any tags even though the name tag exists. Any help with this? When inspecting node['ec2'] it contains the rest of the info besides the tags which appears non-existent.

gem: MissingCredentialsError

Perhaps because of some API changes on the AWS side, this plugin does not want to function. The gem complains that no credentials were provided:

/opt/chef/embedded/lib/ruby/gems/2.4.0/gems/aws-sdk-core-3.21.2/lib/aws-sdk-core/plugins/signature_v4.rb:72:in sign_request': unable to sign request without credentials set (Aws::Errors::MissingCredentialsError)`

If you try to use the gem locally and have your ~/.aws/credentials set up, it works. Not sure if it makes sense to deploy AWS credentials before or with this plugin to the node, or if it's better to look at using the EC2 http endpoint as described at the link below.

Edit: The last line of the http endpoint script that uses aws ec2... to actually fetch the tags, despite having read it, escaped my brain.

https://gist.github.com/codeinthehole/ab9a8dc30917c5705846

EC2Tags dont work on latest windows images

Hey,
I am trying to get it work on windows images both 2012 and 2016, while getting the following error:
[2018-08-05T11:18:53+00:00] DEBUG: Plugin EC2Tags threw #<NameError: uninitialized constant Aws>
[2018-08-05T11:18:53+00:00] DEBUG: C:/chef/ohai/plugins/ec2-tags.rb:25:in rescue in block (2 levels) in <main>' [2018-08-05T11:18:53+00:00] DEBUG: C:/chef/ohai/plugins/ec2-tags.rb:9:in block (2 levels) in

'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/dsl/plugin/versionvii.rb:90:in instance_eval' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/dsl/plugin/versionvii.rb:90:in run_plugin'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/dsl/plugin.rb:102:in run' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/dsl/plugin.rb:185:in safe_run'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/runner.rb:90:in run_v7_plugin' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/runner.rb:47:in block in run_plugin'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/2.4.0/benchmark.rb:293:in measure' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/runner.rb:39:in run_plugin'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/system.rb:105:in block in run_plugins' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/system.rb:104:in each'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/system.rb:104:in run_plugins' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/system.rb:82:in all_plugins'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/application.rb:97:in run_application' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/application.rb:80:in block in run'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/2.4.0/benchmark.rb:293:in measure' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/lib/ohai/application.rb:78:in run'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/embedded/lib/ruby/gems/2.4.0/gems/ohai-13.8.0/bin/ohai:26:in <top (required)>' [2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/bin/ohai:29:in load'
[2018-08-05T11:18:53+00:00] DEBUG: C:/opscode/chef/bin/ohai:29:in `'

Some details:
Base AMI: ami-f7ece81c , also tried: ami-8017156b
Gem version: C:\opscode\chef\embedded\bin\gem list
aws-sdk (2.0.48)
aws-sdk-core (2.0.48)
aws-sdk-resources (2.0.48)

Please assist.
Thanks,
Mor.

Chef::Exceptions::FileNotFound

I am trying to install ec2-tags-ohai-plugin but getting following error on Windows 2016

Chef::Exceptions::FileNotFound

ohai_plugin[ec2-tags] (infra-windows-cookbook::join-computer2AD line 5) had an error: Chef::Exceptions::FileNotFound: template[C:/chef/ohai/plugins/ec2-tags.rb] (C:/chef/cache/cookbooks/ohai
/resources/plugin.rb line 25) had an error: Chef::Exceptions::FileNotFound: Cookbook 'infra-windows-cookbook' (2.0.9) does not contain a file at any of these locations:
templates/windows-10.0.14393/ec2-tags.rb
templates/windows/ec2-tags.rb
templates/default/ec2-tags.rb
templates/ec2-tags.rb

But I could able to see the file under templates/default/ec2-tags.rb in ec2-tags-ohai-plugin cookbook.

Please let me know how to resolve it?

Incompatible with aws cookbook

If I run the current version of ec2-tags-ohai-plugin (0.2.4) and try to use the current version of the aws cookbook, I get the following error:

ERROR: Unable to activate aws-sdk-resources-2.10.61, because aws-sdk-core-3.6.0 conflicts with aws-sdk-core (= 2.10.61)

Because the aws cookbook isn't run as a recipe (it just exposes resource providers), there is no way to control when it executes as far as I can tell.

The aws cookbook includes:

gem 'aws-sdk', '~> 2'

But the ec2-tags-ohai-plugin cookbook has gem entry in metadata; it just uses the chef_gem resource to install it in the recipe, with no version pin.

Adding gem 'aws-sdk', '~> 2' to my the metadata of my cookbook that calls ec2-tags-ohai-plugin seems to fix the issue, as does pinning ec2-tags-ohai-plugin to v0.2.3. If I was calling this cookbook directly in the runlist and then trying to use the aws resources in another cookbook, I don't know how this could be worked around.

Maybe adding an attribute to allow pinning the version of the gem installed using the chef_gem resource would fix the issue?

Plugin doesn't work with ruby aws-sdk version 3.0.0

Today we had an issue where the plugin wasn't populating the node['ec2']['tags'] hash. We tracked it down to an update to the ruby aws-sdk that happened today version 3.0.0. It seems that something is wrong either with their update or they have changed some core functionality with describing tags.

They may have realized their error because they seem to have taken the release off of their github releases page, but the version still exists in the gem repo for ubuntu.

We ended up having to pin the version as of now at 2.10.35. As of right now, I'm unsure what the issue is because the plugin installation doesn't throw any errors when it compiles and installs the sdk for the first time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.