I'm trying to add some custom logic for when a property gets passed in.
My Resource looks like this (website.rb):
def bind( arg = nil )
if arg.nil?
# Split the fqdn on '.' to an array
array = @fqdn.split('.')
# Logic switching based on environment
# Append dev/stage to fqdn as needed for environment
case node.chef_environment
when "dev", "stage"
set_or_return( :bind, "http/*:80:" << array[0] << "#{node.chef_environment}." << array[1] << "." << array[2], :kind_of => String )
else
set_or_return( :bind, "http/*:80:" << @fqdn, :kind_of => String )
end
else
set_or_return( :bind, arg, :kind_of => String )
end
end
property :fqdn, String, name_property: true
property :username, String, default: node['test_iis']['username']
property :password, String, default: node['test_iis']['password']
property :docroot, String, default: "C:\\inetpub\\"
property :no_managed_code, [TrueClass, FalseClass], default: false
actions :create, :delete
default_action :create
action :create do
# Create App Pool
iis_pool "#{new_resource.fqdn}" do
pipeline_mode :Integrated
no_managed_code new_resource.no_managed_code
action :add
end
iis_site "#{new_resource.fqdn}" do
bindings new_resource.bind
path "#{new_resource.docroot}"
application_pool "#{new_resource.fqdn}"
action [:add,:config,:start]
end
# Set the username for the folder
iis_config_property 'username' do
ps_path 'MACHINE/WEBROOT/APPHOST'
filter "system.applicationHost/sites/site[@name='#{new_resource.fqdn}']/application[@path='/']/virtualDirectory[@path='/']"
property 'userName'
value "#{new_resource.username}"
end
# Set the password for the folder
iis_config_property 'password' do
ps_path 'MACHINE/WEBROOT/APPHOST'
filter "system.applicationHost/sites/site[@name='#{new_resource.fqdn}']/application[@path='/']/virtualDirectory[@path='/']"
property 'password'
value "#{new_resource.password}"
end
end
action :delete do
# Delete site
iis_site "#{new_resource.fqdn}" do
action [:stop, :delete]
end
# Delete IIS Pool
iis_pool "#{new_resource.fqdn}" do
action :delete
end
end
Trying call the website resource like:
test_iis_website "test.com" do
docroot "C:\\inetpub\\test"
no_managed_code true
end
and
puts case node.chef_environment
when "dev"
http = "http/*:80:test-dev.com"
when "stage"
http = "http/*:80:test-stage.com"
else
http = "http/*:80:test.com"
end
test_iis_website "test2.com" do
docroot "C:\\inetpub\\test2"
no_managed_code true
bind "#{http}"
end
I'm trying to do logic on "bind" so that if one is passed to just accept it. If one is not passed to derive it from the "fqdn" parameter based on what environment it is in.
When I do the code here it's like it is not picking up the "bind" parameter I am passing in.
I know I can do the logic in my action create but that just doesn't seem like a good solution to me.