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

undefined method `map' for #<String: when using ['beaver']['files'] key #15

Open
muddman opened this issue Sep 2, 2015 · 0 comments
Open

Comments

@muddman
Copy link

muddman commented Sep 2, 2015

This is a great cookbook, thanks for providing it!

I need to override the default tags assigned to /var/log/syslog and /var/log/auth.log in an ubuntu environment but I am getting an error every time I try to use the ['beaver']['files'] key in either a Chef Role or, as in the case below, Opsworks custom json.

I am getting the error **"undefined method map' for #String:0x007f4a1a841dc0"** because map is not expecting a string, but ['beaver']['files']` has to be passed as a string in a role definition or custom json so I'm not sure how to override the default values without modifying the cookbook.

Environment

  • Ubuntu 14.04
  • Chef 11.10.4 running in AWS Opsworks
  • Berksfile: cookbook 'beaver', '~> 1.5.0'

Chef Role / Opsworks Custom json

    "beaver": {
        "version": "31",
        "log_path": "/var/log",
        "log_file": "beaver.log",
        "generate_keypair": "false",
        "files": "[ {'path' => '/var/log/syslog','type' => 'syslog', 'tags' => 'aws,server,syslog'}, {'path' => '/var/log/auth.log', 'type' => 'syslog', 'tags' => 'aws,server,auth'} ]",
        "config_path": "/etc/beaver",
        "config_file": "beaver.conf",
        "pid_file": "/var/run/beaver.pid",
        "user": "root",
        "group": "root",
        "use_virtualenv": "true",
        "configuration": {
            "transport": "rabbitmq",
            "rabbitmq_host": "mq",
            "rabbitmq_port": "5672",
            "rabbitmq_vhost": "vhost",
            "rabbitmq_username": "user",
            "rabbitmq_password": "password",
            "rabbitmq_queue": "logstash_queue",
            "rabbitmq_exchange": "logstash_exchange",
            "rabbitmq_delivery_mode": "1",
            "rabbitmq_queue_durable": "1",
            "rabbitmq_exchange_type": "fanout",
            "logstash_version": "1",
            "respawn_delay": "3",
            "max_failure": "7"
        }
    },

Error Output

When I run beaver::default I get the following error output

[2015-09-02T17:28:10+00:00] INFO: Starting chef-zero on port 8889 with repository at repository at /opt/aws/opsworks/current
One version per cookbook
data_bags at /var/lib/aws/opsworks/data/data_bags
nodes at /var/lib/aws/opsworks/data/nodes

[2015-09-02T17:28:10+00:00] INFO: Forking chef instance to converge...
[2015-09-02T17:28:10+00:00] INFO: *** Chef 11.10.4 ***
[2015-09-02T17:28:10+00:00] INFO: Chef-client pid: 26141
[2015-09-02T17:28:11+00:00] INFO: Setting the run_list to ["opsworks_custom_cookbooks::load", "opsworks_custom_cookbooks::execute"] from JSON
[2015-09-02T17:28:11+00:00] WARN: Run List override has been provided.
[2015-09-02T17:28:11+00:00] WARN: Original Run List: [recipe[opsworks_custom_cookbooks::load], recipe[opsworks_custom_cookbooks::execute]]
[2015-09-02T17:28:11+00:00] WARN: Overridden Run List: [recipe[opsworks_stack_state_sync], recipe[beaver::default], recipe[test_suite], recipe[opsworks_cleanup]]
[2015-09-02T17:28:11+00:00] INFO: Run List is [recipe[opsworks_stack_state_sync], recipe[beaver::default], recipe[test_suite], recipe[opsworks_cleanup]]
[2015-09-02T17:28:11+00:00] INFO: Run List expands to [opsworks_stack_state_sync, beaver::default, test_suite, opsworks_cleanup]
[2015-09-02T17:28:11+00:00] INFO: Starting Chef Run for admin1.localdomain
[2015-09-02T17:28:11+00:00] INFO: Running start handlers
[2015-09-02T17:28:11+00:00] INFO: Start handlers complete.
[2015-09-02T17:28:11+00:00] INFO: HTTP Request Returned 404 Not Found: Object not found: /reports/nodes/admin1.localdomain/runs
[2015-09-02T17:28:23+00:00] INFO: Loading cookbooks [apache2, apt, beaver, build-essential, dependencies, deploy, gem_support, mod_php5_apache2, mysql, nginx, opsworks_agent_monit, opsworks_aws_flow_ruby, opsworks_bundler, opsworks_cleanup, opsworks_commons, opsworks_initial_setup, opsworks_java, opsworks_nodejs, opsworks_rubygems, opsworks_stack_state_sync, packages, passenger_apache2, php, python, rails, ruby, scm_helper, ssh_users, test_suite, unicorn, yum, yum-epel]
[2015-09-02T17:28:24+00:00] WARN: Cloning resource attributes for group[root] from prior resource (CHEF-3694)
[2015-09-02T17:28:24+00:00] WARN: Previous group[root]: /var/lib/aws/opsworks/cache.stage2/cookbooks/beaver/recipes/default.rb:37:in `from_file'
[2015-09-02T17:28:24+00:00] WARN: Current  group[root]: /var/lib/aws/opsworks/cache.stage2/cookbooks/beaver/recipes/default.rb:42:in `from_file'

================================================================================
Recipe Compile Error in /var/lib/aws/opsworks/cache.stage2/cookbooks/beaver/recipes/default.rb
================================================================================


NoMethodError
-------------
undefined method `map' for #<String:0x007f4a1a841dc0>


Cookbook Trace:
---------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/beaver/recipes/default.rb:99:in `from_file'


Relevant File Content:
----------------------
/var/lib/aws/opsworks/cache.stage2/cookbooks/beaver/recipes/default.rb:

92:    action :create
93:    owner node['beaver']['user']
94:    group node['beaver']['group']
95:  end
96:  
97:  include_recipe 'beaver::generate_keypair' if node['beaver']['generate_keypair']
98:  
99>> log_files = node['beaver']['files'].map do |each|
100:    path = each['path']
101:    options = each.reject { |key, _value| key == 'path' }
102:    {
103:      'path' => path,
104:      'options' => options
105:    }
106:  end
107:  
108:  template "#{node['beaver']['config_path']}/#{node['beaver']['config_file']}" do



[2015-09-02T17:28:24+00:00] ERROR: Running exception handlers
[2015-09-02T17:28:24+00:00] ERROR: Exception handlers complete
[2015-09-02T17:28:24+00:00] FATAL: Stacktrace dumped to /var/lib/aws/opsworks/cache.stage2/chef-stacktrace.out
[2015-09-02T17:28:24+00:00] ERROR: undefined method `map' for #<String:0x007f4a1a841dc0>
[2015-09-02T17:28:24+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

Am I using it incorrectly or do you have any thoughts on how I can override the defaults without changing the cookbook?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant