Chef new_resource. vs. The Next CEO of Stack OverflowCheck if a value exists in an array in RubyUnderstanding Chef only_if not_ifMap and Remove nil values in RubyChef Solo - Chef::Exceptions::PrivateKeyMissingHow do I share code across Chef cookbooks in a chef-repo?Chef libraries or definitions?Chef undefined method `use_etag' for Chef::Resource::RemoteFilechef-container + chef-vaultHow to call Chef resource inside ruby_block in Chef?Replace the value in xml using Chef

Pulling the principal components out of a DimensionReducerFunction?

How do I fit a non linear curve?

Reshaping json / reparing json inside shell script (remove trailing comma)

0-rank tensor vs vector in 1D

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Graph of the history of databases

Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?

Where do students learn to solve polynomial equations these days?

TikZ: How to fill area with a special pattern?

Is it professional to write unrelated content in an almost-empty email?

Won the lottery - how do I keep the money?

How to get the last not-null value in an ordered column of a huge table?

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

What is the difference between "hamstring tendon" and "common hamstring tendon"?

In the "Harry Potter and the Order of the Phoenix" video game, what potion is used to sabotage Umbridge's speakers?

Does Germany produce more waste than the US?

Purpose of level-shifter with same in and out voltages

Defamation due to breach of confidentiality

Decide between Polyglossia and Babel for LuaLaTeX in 2019

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

free fall ellipse or parabola?

Are the names of these months realistic?

How to find image of a complex function with given constraints?

Can I calculate next year's exemptions based on this year's refund/amount owed?



Chef new_resource. vs.



The Next CEO of Stack OverflowCheck if a value exists in an array in RubyUnderstanding Chef only_if not_ifMap and Remove nil values in RubyChef Solo - Chef::Exceptions::PrivateKeyMissingHow do I share code across Chef cookbooks in a chef-repo?Chef libraries or definitions?Chef undefined method `use_etag' for Chef::Resource::RemoteFilechef-container + chef-vaultHow to call Chef resource inside ruby_block in Chef?Replace the value in xml using Chef










0















I inherited a cookbook utilizing another cookbook with a custom resource.



I'm trying to figure out the use of the new_resource in this code.



In the code below, path new_resource.fullpath causes a "non-defined method."



When I changed that line to simply path fullpath to reference the local variable, it worked just fine. I can't figure out what the previous intent was.



I'm sure this is an easy one. Looking for an ELI5. Thanks!



Full code Block.



resource_name :mb_worker_role
default_action :create

property :service_name, String, name_property: true
property :root_path, String, required: true
property :executable, String, required: true
property :wcf_port, [Integer, String], default: 808
property :health_port, [Integer, String], default: 8000
property :use_dummy, [TrueClass, FalseClass], default: true

action :create do
# Create firewall allow for WCF port
windows_firewall_rule "#new_resource.service_name - WCF" do
localport new_resource.wcf_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Create firewall allow for health port
windows_firewall_rule "#new_resource.service_name - Health" do
localport new_resource.health_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Full path to service executable at root_pathexecutable
fullpath = "#new_resource.root_path\#new_resource.executable"

# Create directory for worker role application root
directory new_resource.root_path do
recursive true
action :create
end

# Set NetTCPPortSharing to start on demand
windows_service 'NetTCPPortSharing' do
action :configure_startup
startup_type :manual
end

# Stage the dummy worker role executable if requested
# Only used to verify this resource when testing
if property_is_set?(:use_dummy)
cookbook_file 'Stage dummy worker role executable' do
# path new_resource.fullpath
path fullpath
cookbook 'mb_worker_role'
source 'WorkerRole.Default.exe'
only_if new_resource.use_dummy
action :create
end
end

# Create windows service if it does not exist
powershell_script "Installing Windows service #new_resource.service_name" do
code <<-EOH
# Create the Windows service
sc.exe create "#new_resource.service_name" binPath="#fullpath"
EOH
not_if "(Get-Service -Name #new_resource.service_name).Name -eq '#new_resource.service_name'"
end

# Set service to automatic and make sure it's running
windows_service new_resource.service_name do
action [:configure_startup, :enable, :start]
startup_type :automatic
end
end









share|improve this question
























  • It looks like the intent is for 'new_resource' to respond to a method called fullpath. I'm not sure from what you've put whether the problem is that you don't have a variable called 'new_resource', in which case it will say 'Undefined method fullpath for nilclass', or if the variable doesn't respond to that method, which will reference the class of new_resource in the error message

    – Mark
    Mar 8 at 17:15











  • The issue with your change is you'll obviously be using the full_path variable which has already been defined, rather than what I'm guessing the author of that code intended, which is to use whatever value returns from new_resource.full_path

    – Mark
    Mar 8 at 17:16











  • OK ignore the above 2 comments, I just saw the line: fullpath = "#new_resource.root_path\#new_resource.executable"

    – Mark
    Mar 8 at 17:17











  • From that it looks like what you've changed is correct, and that the new_resource object shouldn't be responding to full_path, but used to create the full_path variable in the line above

    – Mark
    Mar 8 at 17:17












  • That's what I thought. I'm not sure what the original authors intent was, but with pull path being defined in the resource, what I changed appears to be the proper action.

    – mbspark
    Mar 8 at 17:41















0















I inherited a cookbook utilizing another cookbook with a custom resource.



I'm trying to figure out the use of the new_resource in this code.



In the code below, path new_resource.fullpath causes a "non-defined method."



When I changed that line to simply path fullpath to reference the local variable, it worked just fine. I can't figure out what the previous intent was.



I'm sure this is an easy one. Looking for an ELI5. Thanks!



Full code Block.



resource_name :mb_worker_role
default_action :create

property :service_name, String, name_property: true
property :root_path, String, required: true
property :executable, String, required: true
property :wcf_port, [Integer, String], default: 808
property :health_port, [Integer, String], default: 8000
property :use_dummy, [TrueClass, FalseClass], default: true

action :create do
# Create firewall allow for WCF port
windows_firewall_rule "#new_resource.service_name - WCF" do
localport new_resource.wcf_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Create firewall allow for health port
windows_firewall_rule "#new_resource.service_name - Health" do
localport new_resource.health_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Full path to service executable at root_pathexecutable
fullpath = "#new_resource.root_path\#new_resource.executable"

# Create directory for worker role application root
directory new_resource.root_path do
recursive true
action :create
end

# Set NetTCPPortSharing to start on demand
windows_service 'NetTCPPortSharing' do
action :configure_startup
startup_type :manual
end

# Stage the dummy worker role executable if requested
# Only used to verify this resource when testing
if property_is_set?(:use_dummy)
cookbook_file 'Stage dummy worker role executable' do
# path new_resource.fullpath
path fullpath
cookbook 'mb_worker_role'
source 'WorkerRole.Default.exe'
only_if new_resource.use_dummy
action :create
end
end

# Create windows service if it does not exist
powershell_script "Installing Windows service #new_resource.service_name" do
code <<-EOH
# Create the Windows service
sc.exe create "#new_resource.service_name" binPath="#fullpath"
EOH
not_if "(Get-Service -Name #new_resource.service_name).Name -eq '#new_resource.service_name'"
end

# Set service to automatic and make sure it's running
windows_service new_resource.service_name do
action [:configure_startup, :enable, :start]
startup_type :automatic
end
end









share|improve this question
























  • It looks like the intent is for 'new_resource' to respond to a method called fullpath. I'm not sure from what you've put whether the problem is that you don't have a variable called 'new_resource', in which case it will say 'Undefined method fullpath for nilclass', or if the variable doesn't respond to that method, which will reference the class of new_resource in the error message

    – Mark
    Mar 8 at 17:15











  • The issue with your change is you'll obviously be using the full_path variable which has already been defined, rather than what I'm guessing the author of that code intended, which is to use whatever value returns from new_resource.full_path

    – Mark
    Mar 8 at 17:16











  • OK ignore the above 2 comments, I just saw the line: fullpath = "#new_resource.root_path\#new_resource.executable"

    – Mark
    Mar 8 at 17:17











  • From that it looks like what you've changed is correct, and that the new_resource object shouldn't be responding to full_path, but used to create the full_path variable in the line above

    – Mark
    Mar 8 at 17:17












  • That's what I thought. I'm not sure what the original authors intent was, but with pull path being defined in the resource, what I changed appears to be the proper action.

    – mbspark
    Mar 8 at 17:41













0












0








0








I inherited a cookbook utilizing another cookbook with a custom resource.



I'm trying to figure out the use of the new_resource in this code.



In the code below, path new_resource.fullpath causes a "non-defined method."



When I changed that line to simply path fullpath to reference the local variable, it worked just fine. I can't figure out what the previous intent was.



I'm sure this is an easy one. Looking for an ELI5. Thanks!



Full code Block.



resource_name :mb_worker_role
default_action :create

property :service_name, String, name_property: true
property :root_path, String, required: true
property :executable, String, required: true
property :wcf_port, [Integer, String], default: 808
property :health_port, [Integer, String], default: 8000
property :use_dummy, [TrueClass, FalseClass], default: true

action :create do
# Create firewall allow for WCF port
windows_firewall_rule "#new_resource.service_name - WCF" do
localport new_resource.wcf_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Create firewall allow for health port
windows_firewall_rule "#new_resource.service_name - Health" do
localport new_resource.health_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Full path to service executable at root_pathexecutable
fullpath = "#new_resource.root_path\#new_resource.executable"

# Create directory for worker role application root
directory new_resource.root_path do
recursive true
action :create
end

# Set NetTCPPortSharing to start on demand
windows_service 'NetTCPPortSharing' do
action :configure_startup
startup_type :manual
end

# Stage the dummy worker role executable if requested
# Only used to verify this resource when testing
if property_is_set?(:use_dummy)
cookbook_file 'Stage dummy worker role executable' do
# path new_resource.fullpath
path fullpath
cookbook 'mb_worker_role'
source 'WorkerRole.Default.exe'
only_if new_resource.use_dummy
action :create
end
end

# Create windows service if it does not exist
powershell_script "Installing Windows service #new_resource.service_name" do
code <<-EOH
# Create the Windows service
sc.exe create "#new_resource.service_name" binPath="#fullpath"
EOH
not_if "(Get-Service -Name #new_resource.service_name).Name -eq '#new_resource.service_name'"
end

# Set service to automatic and make sure it's running
windows_service new_resource.service_name do
action [:configure_startup, :enable, :start]
startup_type :automatic
end
end









share|improve this question
















I inherited a cookbook utilizing another cookbook with a custom resource.



I'm trying to figure out the use of the new_resource in this code.



In the code below, path new_resource.fullpath causes a "non-defined method."



When I changed that line to simply path fullpath to reference the local variable, it worked just fine. I can't figure out what the previous intent was.



I'm sure this is an easy one. Looking for an ELI5. Thanks!



Full code Block.



resource_name :mb_worker_role
default_action :create

property :service_name, String, name_property: true
property :root_path, String, required: true
property :executable, String, required: true
property :wcf_port, [Integer, String], default: 808
property :health_port, [Integer, String], default: 8000
property :use_dummy, [TrueClass, FalseClass], default: true

action :create do
# Create firewall allow for WCF port
windows_firewall_rule "#new_resource.service_name - WCF" do
localport new_resource.wcf_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Create firewall allow for health port
windows_firewall_rule "#new_resource.service_name - Health" do
localport new_resource.health_port.to_s
protocol 'TCP'
firewall_action :allow
end

# Full path to service executable at root_pathexecutable
fullpath = "#new_resource.root_path\#new_resource.executable"

# Create directory for worker role application root
directory new_resource.root_path do
recursive true
action :create
end

# Set NetTCPPortSharing to start on demand
windows_service 'NetTCPPortSharing' do
action :configure_startup
startup_type :manual
end

# Stage the dummy worker role executable if requested
# Only used to verify this resource when testing
if property_is_set?(:use_dummy)
cookbook_file 'Stage dummy worker role executable' do
# path new_resource.fullpath
path fullpath
cookbook 'mb_worker_role'
source 'WorkerRole.Default.exe'
only_if new_resource.use_dummy
action :create
end
end

# Create windows service if it does not exist
powershell_script "Installing Windows service #new_resource.service_name" do
code <<-EOH
# Create the Windows service
sc.exe create "#new_resource.service_name" binPath="#fullpath"
EOH
not_if "(Get-Service -Name #new_resource.service_name).Name -eq '#new_resource.service_name'"
end

# Set service to automatic and make sure it's running
windows_service new_resource.service_name do
action [:configure_startup, :enable, :start]
startup_type :automatic
end
end






ruby chef






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 18:00









anothermh

3,36431733




3,36431733










asked Mar 8 at 17:09









mbsparkmbspark

83




83












  • It looks like the intent is for 'new_resource' to respond to a method called fullpath. I'm not sure from what you've put whether the problem is that you don't have a variable called 'new_resource', in which case it will say 'Undefined method fullpath for nilclass', or if the variable doesn't respond to that method, which will reference the class of new_resource in the error message

    – Mark
    Mar 8 at 17:15











  • The issue with your change is you'll obviously be using the full_path variable which has already been defined, rather than what I'm guessing the author of that code intended, which is to use whatever value returns from new_resource.full_path

    – Mark
    Mar 8 at 17:16











  • OK ignore the above 2 comments, I just saw the line: fullpath = "#new_resource.root_path\#new_resource.executable"

    – Mark
    Mar 8 at 17:17











  • From that it looks like what you've changed is correct, and that the new_resource object shouldn't be responding to full_path, but used to create the full_path variable in the line above

    – Mark
    Mar 8 at 17:17












  • That's what I thought. I'm not sure what the original authors intent was, but with pull path being defined in the resource, what I changed appears to be the proper action.

    – mbspark
    Mar 8 at 17:41

















  • It looks like the intent is for 'new_resource' to respond to a method called fullpath. I'm not sure from what you've put whether the problem is that you don't have a variable called 'new_resource', in which case it will say 'Undefined method fullpath for nilclass', or if the variable doesn't respond to that method, which will reference the class of new_resource in the error message

    – Mark
    Mar 8 at 17:15











  • The issue with your change is you'll obviously be using the full_path variable which has already been defined, rather than what I'm guessing the author of that code intended, which is to use whatever value returns from new_resource.full_path

    – Mark
    Mar 8 at 17:16











  • OK ignore the above 2 comments, I just saw the line: fullpath = "#new_resource.root_path\#new_resource.executable"

    – Mark
    Mar 8 at 17:17











  • From that it looks like what you've changed is correct, and that the new_resource object shouldn't be responding to full_path, but used to create the full_path variable in the line above

    – Mark
    Mar 8 at 17:17












  • That's what I thought. I'm not sure what the original authors intent was, but with pull path being defined in the resource, what I changed appears to be the proper action.

    – mbspark
    Mar 8 at 17:41
















It looks like the intent is for 'new_resource' to respond to a method called fullpath. I'm not sure from what you've put whether the problem is that you don't have a variable called 'new_resource', in which case it will say 'Undefined method fullpath for nilclass', or if the variable doesn't respond to that method, which will reference the class of new_resource in the error message

– Mark
Mar 8 at 17:15





It looks like the intent is for 'new_resource' to respond to a method called fullpath. I'm not sure from what you've put whether the problem is that you don't have a variable called 'new_resource', in which case it will say 'Undefined method fullpath for nilclass', or if the variable doesn't respond to that method, which will reference the class of new_resource in the error message

– Mark
Mar 8 at 17:15













The issue with your change is you'll obviously be using the full_path variable which has already been defined, rather than what I'm guessing the author of that code intended, which is to use whatever value returns from new_resource.full_path

– Mark
Mar 8 at 17:16





The issue with your change is you'll obviously be using the full_path variable which has already been defined, rather than what I'm guessing the author of that code intended, which is to use whatever value returns from new_resource.full_path

– Mark
Mar 8 at 17:16













OK ignore the above 2 comments, I just saw the line: fullpath = "#new_resource.root_path\#new_resource.executable"

– Mark
Mar 8 at 17:17





OK ignore the above 2 comments, I just saw the line: fullpath = "#new_resource.root_path\#new_resource.executable"

– Mark
Mar 8 at 17:17













From that it looks like what you've changed is correct, and that the new_resource object shouldn't be responding to full_path, but used to create the full_path variable in the line above

– Mark
Mar 8 at 17:17






From that it looks like what you've changed is correct, and that the new_resource object shouldn't be responding to full_path, but used to create the full_path variable in the line above

– Mark
Mar 8 at 17:17














That's what I thought. I'm not sure what the original authors intent was, but with pull path being defined in the resource, what I changed appears to be the proper action.

– mbspark
Mar 8 at 17:41





That's what I thought. I'm not sure what the original authors intent was, but with pull path being defined in the resource, what I changed appears to be the proper action.

– mbspark
Mar 8 at 17:41












1 Answer
1






active

oldest

votes


















0














path fullpath is a magical alias system that we actively discourage at this point. It was a nice thing to try, but the syntax has a lot of problems that result in unexpected behavior. Use new_resource.fullpath, far fewer footguns.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067888%2fchef-new-resource-value-vs-value%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    path fullpath is a magical alias system that we actively discourage at this point. It was a nice thing to try, but the syntax has a lot of problems that result in unexpected behavior. Use new_resource.fullpath, far fewer footguns.






    share|improve this answer



























      0














      path fullpath is a magical alias system that we actively discourage at this point. It was a nice thing to try, but the syntax has a lot of problems that result in unexpected behavior. Use new_resource.fullpath, far fewer footguns.






      share|improve this answer

























        0












        0








        0







        path fullpath is a magical alias system that we actively discourage at this point. It was a nice thing to try, but the syntax has a lot of problems that result in unexpected behavior. Use new_resource.fullpath, far fewer footguns.






        share|improve this answer













        path fullpath is a magical alias system that we actively discourage at this point. It was a nice thing to try, but the syntax has a lot of problems that result in unexpected behavior. Use new_resource.fullpath, far fewer footguns.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 12 at 2:05









        coderangercoderanger

        30.5k32846




        30.5k32846





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067888%2fchef-new-resource-value-vs-value%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

            Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

            How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page