I'm using the latest apache2 cookbook (v5.0.0) in a wrapper file. my wrapper recipe is just including the apache2 recipe so I'm not sure what is causing this error in my kitchen test when I try to setup the test suite???
Wrapper Recipe
include_recipe 'apache2'
kitchen setup Error
...
Synchronizing Cookbooks:
- my-webapp (2.0.0)
- apache2 (5.0.0)
Installing Cookbook Gems:
Compiling Cookbooks...
================================================================================
Recipe Compile Error in /tmp/kitchen/cache/cookbooks/apache2/attributes/default.rb
================================================================================
TypeError
---------
no implicit conversion of String into Integer
Cookbook Trace:
---------------
/tmp/kitchen/cache/cookbooks/apache2/attributes/default.rb:90:in `from_file'
Relevant File Content:
----------------------
/tmp/kitchen/cache/cookbooks/apache2/attributes/default.rb:
83: default['apache']['pid_file'] = '/var/run/httpd2.pid'
84: default['apache']['lib_dir'] = node['kernel']['machine'] =~ /^i[36]86$/ ? '/usr/lib/apache2' : '/usr/lib64/apache2'
85: default['apache']['libexec_dir'] = node['apache']['lib_dir']
86: when 'debian'
87: default['apache']['package'] = 'apache2'
88: default['apache']['perl_pkg'] = 'perl'
89: default['apache']['devel_package'] =
90>> if node['apache']['mpm'] == 'prefork'
91: 'apache2-prefork-dev'
92: else
93: 'apache2-dev'
94: end
95: default['apache']['apachectl'] = '/usr/sbin/apache2ctl'
96: default['apache']['dir'] = '/etc/apache2'
97: default['apache']['log_dir'] = '/var/log/apache2'
98: default['apache']['error_log'] = 'error.log'
99: default['apache']['access_log'] = 'access.log'
System Info:
------------
chef_version=13.0.118
platform=ubuntu
platform_version=16.04
ruby=ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
program_name=chef-client worker: ppid=3084;start=16:38:30;
executable=/opt/chef/bin/chef-client
As engineersmnky mentioned, check the override and normal level attributes (or defaults coming from roles/envs). The sneaky one is usually normal, check via knife node edit. The likely case is node['apache'] being set to an Array.
Related
On windows 10, i am using ruby 2.7.0.
Using 'fiddle', I try to open a dll in my ruby script but i receive an error message on line "Fiddle.dlopen".
There is my ruby code :
require 'fiddle'
filename = File.join(__dir__, "Circle.dll")
circle = Fiddle.dlopen(filename)
compute_ray = Fiddle::Function.new(
circle['ComputeRay'],
[Fiddle::TYPE_DOUBLE, Fiddle::TYPE_DOUBLE],
Fiddle::TYPE_DOUBLE
)
r = compute_ray.call(100,5)
puts "ray = #{r}"
"Circle.dll" has been compiled from this repo : https://github.com/chaudard/Circle
There is the error message :
Traceback (most recent call last):
3: from use_dll.rb:6:in `<main>'
2: from /usr/lib/ruby/2.7.0/fiddle.rb:47:in `dlopen'
1: from /usr/lib/ruby/2.7.0/fiddle.rb:47:in `new'
/usr/lib/ruby/2.7.0/fiddle.rb:47:in `initialize': /home/user/code/ruby/dll/Circle.dll: Exec format error (Fiddle::DLError)
Thanks for your help.
I am trying to instal node on a fresh vagrant box using puppet however when running the manifest i get the following errors on the box.
Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
Warning: Scope(Apt::Source[nodesource]): $include_src is deprecated and will be removed in the next major release, please use $include => { 'src' => false } instead
Warning: Scope(Apt::Source[nodesource]): $required_packages is deprecated and will be removed in the next major release, please use package resources instead.
Warning: Scope(Apt::Source[nodesource]): $key_source is deprecated and will be removed in the next major release, please use $key => { 'source' => https://deb.nodesource.com/gpgkey/nodesource.gpg.key } instead.
Warning: Scope(Apt::Key[Add key: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280 from Apt::Source nodesource]): $key_source is deprecated and will be removed in the next major release. Please use $source instead.
Error: undefined method `ref' for nil:NilClass on node vagrant-ubuntu-trusty-64.efiling.local
Error: undefined method `ref' for nil:NilClass on node vagrant-ubuntu-trusty-64.efiling.local
My vagrant file looks like this:
config.vm.provision :shell do |shell|
shell.inline = "mkdir -p /etc/puppet/modules;
puppet module install puppetlabs-apt;
puppet module install puppetlabs/nodejs"
end
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "default.pp"
end
This is my manifest file:
class { 'nodejs': }
The next part is to get vagrant to run the manifest file but I believe these errors are stopping this from happening.
This is all relatively new to me so looking for some guidance on the issue.
you should replace puppetlabs/nodejs by puppetlabs-nodejs so your Vagrantfile will look like
config.vm.provision :shell do |shell|
shell.inline = "mkdir -p /etc/puppet/modules;
puppet module install puppetlabs-apt;
puppet module install puppetlabs-nodejs"
end
Which version of puppet are you using ? I had to upgrade to newer version on my ubuntu box to make it work, I upgrade to puppet v3.8.4 to make it work - see below the log
==> default: Running provisioner: puppet...
==> default: Running Puppet with default.pp...
==> default: stdin: is not a tty
==> default: Warning: Setting templatedir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations
==> default: (at /usr/lib/ruby/vendor_ruby/puppet/settings.rb:1139:in `issue_deprecation_warning')
==> default: Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
==> default: Warning: Scope(Apt::Source[nodesource]): $include_src is deprecated and will be removed in the next major release, please use $include => { 'src' => false } instead
==> default: Warning: Scope(Apt::Source[nodesource]): $required_packages is deprecated and will be removed in the next major release, please use package resources instead.
==> default: Warning: Scope(Apt::Source[nodesource]): $key_source is deprecated and will be removed in the next major release, please use $key => { 'source' => https://deb.nodesource.com/gpgkey/nodesource.gpg.key } instead.
==> default: Warning: Scope(Apt::Key[Add key: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280 from Apt::Source nodesource]): $key_source is deprecated and will be removed in the next major release. Please use $source instead.
==> default: Notice: Compiled catalog for ubuntu.localdomain in environment production in 0.71 seconds
==> default: Notice: /Stage[main]/Apt/Apt::Setting[conf-update-stamp]/File[/etc/apt/apt.conf.d/15update-stamp]/ensure: defined content as '{md5}0962d70c4ec78bbfa6f3544ae0c41974'
==> default: Notice: /Stage[main]/Apt/File[preferences]/ensure: created
==> default: Notice: /Stage[main]/Nodejs::Repo::Nodesource/Nodejs::Repo::Nodesource::Apt/Apt::Source[nodesource]/Apt::Key[Add key: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280 from Apt::Source nodesource]/Apt_key[Add key: 9FD3B784BC1C6FC31A8A0A1C1655A0AB68576280 from Apt::Source nodesource]/ensure: created
==> default: Notice: /Stage[main]/Nodejs::Repo::Nodesource/Nodejs::Repo::Nodesource::Apt/Apt::Source[nodesource]/Apt::Setting[list-nodesource]/File[/etc/apt/sources.list.d/nodesource.list]/ensure: created
==> default: Notice: /Stage[main]/Apt::Update/Exec[apt_update]/returns: E: The method driver /usr/lib/apt/methods/https could not be found.
==> default: Error: /Stage[main]/Apt::Update/Exec[apt_update]: Failed to call refresh: /usr/bin/apt-get update returned 100 instead of one of [0]
==> default: Error: /Stage[main]/Apt::Update/Exec[apt_update]: /usr/bin/apt-get update returned 100 instead of one of [0]
==> default: Notice: /Stage[main]/Nodejs::Install/Package[nodejs]/ensure: ensure changed 'purged' to 'present'
==> default: Notice: Finished catalog run in 29.83 seconds
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
fhenri#machine:~/project/examples/vagrant/ubuntu$ vagrant ssh
Welcome to Ubuntu 12.04.1 LTS (GNU/Linux 3.2.0-29-virtual x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Thu Nov 19 06:46:10 2015 from 172.16.42.1
vagrant#ubuntu:~$ node -v
v0.6.12
--- This is an alternative method
This took a while to de-bug but the best approach I found to installing node on a server through puppet is to run a manual instal through puppet.
I found this repo, and took what I needed from the manifest file.
class apt_update {
exec { "aptGetUpdate":
command => "sudo apt-get update",
path => ["/bin", "/usr/bin"]
}
}
class othertools {
package { "git":
ensure => latest,
require => Exec["aptGetUpdate"]
}
package { "vim-common":
ensure => latest,
require => Exec["aptGetUpdate"]
}
package { "curl":
ensure => present,
require => Exec["aptGetUpdate"]
}
package { "htop":
ensure => present,
require => Exec["aptGetUpdate"]
}
package { "g++":
ensure => present,
require => Exec["aptGetUpdate"]
}
}
class nodejs {
exec { "git_clone_n":
command => "git clone https://github.com/visionmedia/n.git /home/vagrant/n",
path => ["/bin", "/usr/bin"],
require => [Exec["aptGetUpdate"], Package["git"], Package["curl"], Package["g++"]]
}
exec { "install_n":
command => "make install",
path => ["/bin", "/usr/bin"],
cwd => "/home/vagrant/n",
require => Exec["git_clone_n"]
}
exec { "install_node":
command => "n stable",
path => ["/bin", "/usr/bin", "/usr/local/bin"],
require => [Exec["git_clone_n"], Exec["install_n"]]
}
}
include apt_update
include othertools
include nodejs
I have been trying to learn Chef and trying to test a small Chef cookbook that would do dcpromo of a Windows 2008 R2 server.
I don't remember exactly where I got the two files originally, but I was able to get it working.
The original dcpromo_unattend.txt.erb file was:
[DCINSTALL]
SafeModeAdminPassword=<%= #admin_password %>
RebootOnCompletion=Yes
ReplicaOrNewDomain=domain
NewDomain=forest
NewDomainDNSName=<%= #domain_name %>
ForestLevel=3
DomainLevel=3
InstallDNS=yes
and the default.rb had this part in it:
template dcpromo_file do
source "dcpromo_unattend.txt.erb"
variables({
:admin_password => '',
:domain_name => ''
})
end
I wasn't quite sure what how to pass in the admin_password and domain_name parameters, so I hard-coded both in the dcpromo_unattend.txt.erb file, and, after some tweaking, was able to make the cookbook work.
Now, I'd like to be able to put the admin_password and domain_name values into a databag, so I tried adding:
begin
dcpromote = Chef::DataBagItem.load(:dcpromote, :main)
rescue
Chef::Log.fatal("Could not find the 'main' item in the 'dcpromote' data bag - Raising fatal error!!")
raise
end
and changed the original template section to:
template dcpromo_file do
source "dcpromo_unattend.txt.erb"
variables({
:admin_password => dcpromote['admin_password'],
:domain_name => dcpromote['domain_name']
})
end
and I created a databag named "dcpromote", but that doesn't seem to be working.
Can someone explain how the original template code is supposed to work, i.e., where is it suppose to be retrieving the admin_password and domain_name parameters from?
Also, can anyone tell me what is wrong with the changes that I made to get this to read the admin_password and domain_name from the "dcpromote" databag?
Thanks,
Jim
EDIT: I guess that I've been staring at this for a few more hours, and, actually, I don't even understand how what I did is working.
What I mean is the erb file I have has the password and domain hard-coded:
[DCINSTALL]
SafeModeAdminPassword=xxxxxxxxx
RebootOnCompletion=Yes
ReplicaOrNewDomain=domain
NewDomain=forest
NewDomainDNSName=WHATEVER.com
ForestLevel=4
DomainLevel=4
InstallDNS=yes
Notice that there is NO reference to admin_password or domain_name in that file.
So, how does this part of the recipe/default.rb even working?
template dcpromo_file do
source "dcpromo_unattend.txt.erb"
variables({
:admin_password => '',
:domain_name => ''
})
end
Can someone explain exactly what this part of the recipe code is doing:
variables({
:admin_password => '',
:domain_name => ''
})
??
Thanks,
Jim
EDIT 2:
Adding entire default.rb after changes suggested by #Draco Ater:
#
# Cookbook Name:: dcpromote
# Recipe:: default
#
# Copyright (c) 2015 The Authors, All Rights Reserved.
#
class ServerHelper
extend ::Windows::Helper
class << self
def dism
##dism ||= locate_sysnative_cmd("dism.exe")
end
def powershell
##powershell ||= locate_sysnative_cmd('WindowsPowershell\v1.0\powershell.exe')
end
def feature_installed?(feature)
cmd = Mixlib::ShellOut.new("#{dism} /online /Get-Features", {:returns => [0,42,127]}).run_command
!!(cmd.stderr.empty? && (cmd.stdout =~ /^Feature Name : #{feature}.?$\n^State : Enabled.?$/i))
end
end
end
windows_reboot 60 do
action :nothing
end
#
# Following snippet from: https://supermarket.chef.io/cookbooks/ad
# This snippet checks for presence of a databag named "dcpromote" and for presence
# of an item in the databag named "main". If that item is not present, then
# this snippet logs a fatal error.
begin
dcpromote = Chef::DataBagItem.load('dcpromote', 'main')
rescue
Chef::Log.fatal("Could not find the 'main' item in the 'dcpromote' data bag - Raising fatal error!!")
raise
end
directory Chef::Config[:file_cache_path]
dcpromo_file = File.join(Chef::Config[:file_cache_path], 'dcpromo_unattend.txt')
#cert_script = File.join(Chef::Config[:file_cache_path], 'setupca.vbs')
# Available from e.g. http://blogs.technet.com/b/pki/archive/2009/09/18/automated-ca-installs-using-vb-script-on-windows-server-2008-and-2008r2.aspx
template dcpromo_file do
source "dcpromo_unattend.txt.erb"
variables(
:admin_password => dcpromote['admin_password'],
:domain_name => dcpromote['domain_name']
)
end
powershell_script "run_dcpromo" do
code "dcpromo /unattend:#{dcpromo_file}"
#notifies :request, 'windows_reboot[60]'
not_if { ServerHelper.feature_installed? 'DirectoryServices-DomainController' }
end
windows_feature 'DirectoryServices-DomainController' do
action :install
#notifies :request, 'windows_reboot[60]'
end
This cookbook/recipe is STILL not working with the databag.
To clarify: When I run it with the earlier code with the hard-coded setting of admin_password and domain_name, it works.
However, if I try the code that uses the databag it doesn't work. When I run it with the databag:
1) [This is strange]: If I look at the "unattended" txt file during the run, it looks like it is populated, but then at the end, the password item is set to nothing, i.e., the unattended text file changes during the run.
2) In the end when the Powershell is run, it looks like it gets an error 32.
Here's the console output:
PS C:\Users\Administrator> chef-client -o dcpromote_usedatabag
Starting Chef Client, version 12.3.0
[2015-06-14T07:24:47-07:00] INFO: *** Chef 12.3.0 ***
[2015-06-14T07:24:47-07:00] INFO: Chef-client pid: 260
[2015-06-14T07:25:04-07:00] WARN: Run List override has been provided.
[2015-06-14T07:25:04-07:00] WARN: Original Run List: []
[2015-06-14T07:25:04-07:00] WARN: Overridden Run List: [recipe[dcpromote_usedatabag]]
[2015-06-14T07:25:04-07:00] INFO: Run List is [recipe[dcpromote_usedatabag]]
[2015-06-14T07:25:04-07:00] INFO: Run List expands to [dcpromote_usedatabag]
[2015-06-14T07:25:04-07:00] INFO: Starting Chef Run for node8
[2015-06-14T07:25:04-07:00] INFO: Running start handlers
[2015-06-14T07:25:04-07:00] INFO: Start handlers complete.
[2015-06-14T07:25:04-07:00] INFO: HTTP Request Returned 404 Not Found:
resolving cookbooks for run list: ["dcpromote_usedatabag"]
[2015-06-14T07:25:04-07:00] INFO: Loading cookbooks [dcpromote_usedatabag#0.1.1, windows#1.37.0, che
[2015-06-14T07:25:04-07:00] INFO: Skipping removal of obsoleted cookbooks from the cache
Synchronizing Cookbooks:
[2015-06-14T07:25:04-07:00] INFO: Storing updated cookbooks/dcpromote_usedatabag/recipes/default.rb
[2015-06-14T07:25:04-07:00] INFO: Storing updated cookbooks/dcpromote_usedatabag/templates/default/d
erb in the cache.
[2015-06-14T07:25:04-07:00] INFO: Storing updated cookbooks/dcpromote_usedatabag/Berksfile in the ca
[2015-06-14T07:25:04-07:00] INFO: Storing updated cookbooks/dcpromote_usedatabag/.kitchen.yml in the
- windows
- chef_handler
[2015-06-14T07:25:04-07:00] INFO: Storing updated cookbooks/dcpromote_usedatabag/chefignore in the c
[2015-06-14T07:25:04-07:00] INFO: Storing updated cookbooks/dcpromote_usedatabag/metadata.rb in the
[2015-06-14T07:25:04-07:00] INFO: Storing updated cookbooks/dcpromote_usedatabag/README.md in the ca
- dcpromote_usedatabag
Compiling Cookbooks...
[2015-06-14T07:25:04-07:00] INFO: +++++++++++++++++++++++++++ HI ++++++++++++++++++++++++++++
[2015-06-14T07:25:04-07:00] INFO: +++++++++++++++++++++++++++ HI ++++++++++++++++++++++++++++
[2015-06-14T07:25:04-07:00] INFO: +++++++++++++++++++++++++++ In template +++++++++++++++++++++++++
[2015-06-14T07:25:04-07:00] INFO: +++++++++++++++++++++++++++ In template +++++++++++++++++++++++++
[2015-06-14T07:25:04-07:00] INFO: ++++ xoutput = [123]
Converging 5 resources
Recipe: dcpromote_usedatabag::default
* windows_reboot[60] action nothing[2015-06-14T07:25:04-07:00] INFO: Processing windows_reboot[60]
romote_usedatabag::default line 28)
(skipped due to action :nothing)
* directory[c:/chef/cache] action create[2015-06-14T07:25:04-07:00] INFO: Processing directory[c:/
reate (dcpromote_usedatabag::default line 47)
(up to date)
* template[c:/chef/cache/dcpromo_unattend.txt] action create[2015-06-14T07:25:04-07:00] INFO: Proc
hef/cache/dcpromo_unattend.txt] action create (dcpromote_usedatabag::default line 52)
[2015-06-14T07:25:04-07:00] INFO: template[c:/chef/cache/dcpromo_unattend.txt] created file c:/chef/
nd.txt
- create new file c:/chef/cache/dcpromo_unattend.txt[2015-06-14T07:25:04-07:00] INFO: template[c
_unattend.txt] updated file contents c:/chef/cache/dcpromo_unattend.txt
- update content in file c:/chef/cache/dcpromo_unattend.txt from none to 798057
--- c:/chef/cache/dcpromo_unattend.txt 2015-06-14 07:25:04.000000000 -0700
+++ C:/Users/ADMINI~1/AppData/Local/Temp/chef-rendered-template20150614-260-1cvaiw 2015-06-14 0
700
## -1 +1,10 ##
+[DCINSTALL]
+SafeModeAdminPassword=P#ssw0rd$123
+RebootOnCompletion=Yes
+ReplicaOrNewDomain=domain
+NewDomain=forest
+NewDomainDNSName=whateverisforever123.com
+ForestLevel=4
+DomainLevel=4
+InstallDNS=yes
* powershell_script[run_dcpromo] action run[2015-06-14T07:25:04-07:00] INFO: Processing powershell
action run (dcpromote_usedatabag::default line 68)
================================================================================
Error executing action `run` on resource 'powershell_script[run_dcpromo]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '32'
---- Begin output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrest
None -File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20150614-260-dfo5yi.ps1" ----
STDOUT:
STDERR:
---- End output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestri
ne -File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20150614-260-dfo5yi.ps1" ----
Ran "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -InputForm
ers/ADMINI~1/AppData/Local/Temp/chef-script20150614-260-dfo5yi.ps1" returned 32
Resource Declaration:
---------------------
# In c:/chef/cache/cookbooks/dcpromote_usedatabag/recipes/default.rb
68: powershell_script "run_dcpromo" do
69: code "dcpromo /unattend:#{dcpromo_file}"
70: #notifies :request, 'windows_reboot[60]'
71: not_if { ServerHelper.feature_installed? 'DirectoryServices-DomainController' }
72: end
73:
Compiled Resource:
------------------
# Declared in c:/chef/cache/cookbooks/dcpromote_usedatabag/recipes/default.rb:68:in `from_file'
powershell_script("run_dcpromo") do
action "run"
retries 0
retry_delay 2
default_guard_interpreter :powershell_script
command "run_dcpromo"
backup 5
returns 0
code "dcpromo /unattend:c:/chef/cache/dcpromo_unattend.txt"
interpreter "powershell.exe"
declared_type :powershell_script
cookbook_name "dcpromote_usedatabag"
recipe_name "default"
not_if { #code block }
end
[2015-06-14T07:26:22-07:00] INFO: Running queued delayed notifications before re-raising exception
Running handlers:
[2015-06-14T07:26:22-07:00] ERROR: Running exception handlers
Running handlers complete
[2015-06-14T07:26:22-07:00] ERROR: Exception handlers complete
[2015-06-14T07:26:22-07:00] FATAL: Stacktrace dumped to c:/chef/cache/chef-stacktrace.out
Chef Client failed. 1 resources updated in 98.15625 seconds
[2015-06-14T07:26:22-07:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: powershell_script[run_dcpro
tabag::default line 68) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit
ved '32'
---- Begin output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestrict
-File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20150614-260-dfo5yi.ps1" ----
STDOUT:
STDERR:
---- End output of "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestricted
File "C:/Users/ADMINI~1/AppData/Local/Temp/chef-script20150614-260-dfo5yi.ps1" ----
Ran "powershell.exe" -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Unrestricted -InputFormat N
ADMINI~1/AppData/Local/Temp/chef-script20150614-260-dfo5yi.ps1" returned 32
PS C:\Users\Administrator>
And here's the unattended txt file at the end:
[DCINSTALL]
SafeModeAdminPassword=
RebootOnCompletion=Yes
ReplicaOrNewDomain=domain
NewDomain=forest
NewDomainDNSName=whateverisforever123.com
ForestLevel=4
DomainLevel=4
InstallDNS=yes
Why is the unattended txt file changing twice during the run (and why is the password value disappearing)?
Thanks,
Jim
EDIT 3:
For the record, I was able to get this working by adding an additional parameter to the template file for setting the netbios name:
[DCINSTALL]
RebootOnCompletion=Yes
ReplicaOrNewDomain=domain
NewDomain=forest
SafeModeAdminPassword=<%= #admin_password %>
NewDomainDNSName=<%= #domain_name %>
ForestLevel=4
DomainLevel=4
InstallDNS=yes
DomainNetbiosName=<%= #domain_netbios_name %>
and then modified the default.rb to set that parameter:
template dcpromo_file do
source "dcpromo_unattend.txt.erb"
variables(
:admin_password => dcpromote['admin_password'],
:domain_netbios_name => dcpromote['domain_netbios_name'],
:domain_name => dcpromote['domain_name']
)
Jim
Let's start with the template file itself.
[DCINSTALL]
SafeModeAdminPassword=<%= #admin_password %>
RebootOnCompletion=Yes
ReplicaOrNewDomain=domain
NewDomain=forest
NewDomainDNSName=<%= #domain_name %>
ForestLevel=3
DomainLevel=3
InstallDNS=yes
The code inside <% %> is ruby code. Things that start with # inside the <% %> are variables. The = is a shorthand for printing the value. So the template uses 2 variables to set the values, by just printing them out.
Where do the variables come from? Exactly from this code in recipe ({ and } are not necessary here):
variables(
:admin_password => '',
:domain_name => ''
)
Currently they are initialized by empty strings, but if you put something else there in the recipe, it will be changed in template too. It will not break, if you pass some variables that are not used in the template, it will just be the redundant code.
For now you can put your password and domain name there like that and get this working (producing the right configuration file on target machine)
variables(
:admin_password => 'my_pass',
:domain_name => 'localhost'
)
Now we want to move the values to the data bag. Create a 'dcpromote' databag with 'main' data bag item.
knife data bag create dcpromote main
and edit the json file. In the end you should have something like that:
{
"id": "main", # <= data bag item name
"admin_password": "my_pass",
"domain_name": "localhost"
}
Then in the recipe you read the data bag into the variable (Try using strings, not symbols, as data bag and item name):
begin
dcpromote = Chef::DataBagItem.load( 'dcpromote', 'main' )
rescue
Chef::Log.fatal("Could not find the 'main' item in the 'dcpromote' data bag - Raising fatal error!!")
raise
end
and use it when creating configuration file:
variables(
:admin_password => dcpromote['admin_password'],
:domain_name => dcpromote['domain_name']
)
I am using Chef provisioning to create machines in AWS. When creating the machine, I add an attribute to it that is an array of JSON files. In the recipes I run, I want to iterate over this array and create a template file on the machine. The machine gets provisioned but when iterating over the array attribute, I get an error that says:
undefined method `each' for nil:NilClass
I tried looking at the node file that got created on my server and guess what? The array of JSON files was added to the node file! I'm not sure why then it keeps throwing that error. Any ideas?
The code sample is as follows:
machines.rb
def get_cluster_json(domain_number)
clusters = []
##environment_template['domains'][domain_number]['clusters'].each do |cls|
clusters << JSON.parse(::File::read(new_resource.template_path + cls))
end
return clusters
end
provisioning_xyz_machine "test-admin" do
tag "usage:keep"
attribute "clusters_json", get_cluster_json(domain_counter)
recipe admin_role
machine_options get_machine_options()
ohai_hints ohai_hints
action $provisioningAction
end
admin_role.rb
managed_details = []
node["clusters_json"].each do |cls|
managed_details << "#{cls['cluster']['name']}"
end
Log
* template[/tools/appsw/appsautm/config/INTFIN_config] action create[2015-05-12T10:24:13-07:00] INFO: Processing template[/tools/appsw/appsautm/config/INTFIN_config] action create (xyz-environment-cookbook::build_admin line 32)
================================================================================
Error executing action `create` on resource 'template[/tools/appsw/appsautm/config/INTFIN_config]'
================================================================================
Chef::Mixin::Template::TemplateError
------------------------------------
undefined method 'each' for `nil:NilClass`
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/xyz-environment-cookbook/recipes/build_admin.rb
32: template "/tools/appsw/appsautm/config/#{env_name}_config" do
33: source "#{env_name}_config.conf.erb"
34: cookbook "appsautm-template"
35: owner node['xyz-dir-library']['user']
36: mode "0755"
37:
38: variables({
39: :admin_servers=> admin_details,
40: :managed_servers=> managed_details
41: })
42: end
43:
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/xyz-environment-cookbook/recipes/build_admin.rb:32:in `from_file'
The error appears to be in your template, not your cookbook. In fact, it appears completely unrelated to the files you posted. I'd need to see the #{env_name}_config.conf.erb file and the build_admin.rb file in order to be more help than that.
i'm trying to learn about chef (i use to wok with CFengine).
So i wanted to install a chef-server on my ubuntu 12.10 box.
I have follow this documentation:
http://docs.opscode.com/install_server.html
All works fine, except i already have a web server listening on port 80. So i wanted nginx (from chef server) to listen on 8080. To do that, i have added "/etc/chef-server/chef-server.rb" with:
default['chef_server']['api_version'] = "11.0.2"
default['chef_server']['flavor'] = "osc" # Open Source Chef
default['chef_server']['notification_email'] = "XXXXXX#SPAM.XXXXX"
default['chef_server']['bootstrap']['enable'] = true
####
# The Chef User that services run as
####
# The username for the chef services user
default['chef_server']['user']['username'] = "chef_server"
# The shell for the chef services user
default['chef_server']['user']['shell'] = "/bin/sh"
# The home directory for the chef services user
default['chef_server']['user']['home'] = "/opt/chef-server/embedded"
####
# Nginx
####
default['chef_server']['nginx']['enable'] = true
default['chef_server']['nginx']['ha'] = false
default['chef_server']['nginx']['dir'] = "/var/opt/chef-server/nginx"
default['chef_server']['nginx']['log_directory'] = "/var/log/chef-server/nginx"
default['chef_server']['nginx']['ssl_port'] = 443
default['chef_server']['nginx']['enable_non_ssl'] = false
default['chef_server']['nginx']['non_ssl_port'] = 8080
default['chef_server']['nginx']['server_name'] = node['fqdn']
default['chef_server']['nginx']['url'] = "https://#{node['fqdn']}"
And when i try: chef-server-ctl reconfigure
I got:
root#goldorak:/etc/chef-server# chef-server-ctl reconfigure
Starting Chef Client, version 11.6.0
Compiling Cookbooks...
Recipe: chef-server::default
* directory[/etc/chef-server] action create (up to date)
================================================================================
Recipe Compile Error in /opt/chef-server/embedded/cookbooks/chef-server/recipes/default.rb
================================================================================
ArgumentError
-------------
wrong number of arguments (0 for 1)
Cookbook Trace:
---------------
/opt/chef-server/embedded/cookbooks/chef-server/recipes/default.rb:34:in `from_file'
Relevant File Content:
----------------------
/opt/chef-server/embedded/cookbooks/chef-server/recipes/default.rb:
27: end.run_action(:create)
28:
29: if File.exists?("/etc/chef-server/chef-server.json")
30: Chef::Log.warn("Please move to /etc/chef-server/chef-server.rb for configuration - /etc/chef-server/chef-server.json is deprecated.")
31: else
32: ChefServer[:node] = node
33: if File.exists?("/etc/chef-server/chef-server.rb")
34>> ChefServer.from_file("/etc/chef-server/chef-server.rb")
35: end
36: node.consume_attributes(ChefServer.generate_config(node['fqdn']))
37: end
38:
39: if File.exists?("/var/opt/chef-server/bootstrapped")
40: node.set['chef_server']['bootstrap']['enable'] = false
41: end
42:
43: # Create the Chef User
[2014-01-30T17:09:54+01:00] ERROR: Running exception handlers
[2014-01-30T17:09:54+01:00] ERROR: Exception handlers complete
[2014-01-30T17:09:54+01:00] FATAL: Stacktrace dumped to /opt/chef-server/embedded/cookbooks/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated
[2014-01-30T17:09:54+01:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Ok answer myself, bad syntax in chef-server.rb. Don't need "default['chef_server']" prefix.
For example:
nginx['non_ssl_port'] = 8080