Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7445661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:58:52+00:00 2026-05-29T11:58:52+00:00

Consider a simple app server / database server setup. You want to set some

  • 0

Consider a simple app server / database server setup. You want to set some value on the app server that tells it where the database server is, and you want to set some permissions on the database server to only allow connections from the app server.

search(:node, “role:db-server”)

and

search(:node, “role:app-server”)

can work from either machine’s recipe run to get you the information you need. But what if the one server doesn’t exist at the time you do the search? Is there a way to say “don’t continue this run” and mark it as not completed, so that the next time chef-client is run on that machine, it will try again?

Alternatively, is there some nifty chef-fu that I’m missing that serves this use case (“notifies” and “subscribes” seem like they’d almost be what I want, except as far as I can tell, they’re only concerned with stuff happening within a node) better? The other thing I’m considering is trying to set up a sleep/check loop to effectively pause one execution run while the other server gets to where it needs to be, but that solution seems rather inelegant and prone to deadlock issues with more complex setups.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:58:54+00:00Added an answer on May 29, 2026 at 11:58 am

    Figured it out. I’m sure this could be made a little more elegant, but here are the basics. Considering you have a file /etc/test.txt that has to be populated with some information from your db server once it has come up and registered itself with chef, you’d do something like the following for your app-server node’s recipe:

    ruby_block "edit test.txt" do
        block do
            db_server = search(:node, %Q{role:db-server})
            rc = Chef::Util::FileEdit.new("/etc/test.txt")
            rc.search_file_replace_line(/^replace_this/, "db_server: #{db_server[0][:hostname]}")
            rc.write_file
        end
        action :create
        ignore_failure true
    end
    

    The key part is “ignore_failure true”. This causes the recipe to re-run every time you restart chef-client on that server. I haven’t figured out how to get it to stop running once it’s successful, but even if that turns out to not be possible, with proper checking, you could avoid re-modifying a file that should not be re-modified if that’s a problem. Note that db_server[0] will cause the recipe to fail if there’s no db server found (I believe this could be made a little more explicit by adding it in a not_if section and checking the length of the search results).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following simple C program that read a file into a buffer and
I have a single AMQ queue that receives simple messages with string body. Consider
I'm in lean startup mode, working on a simple phone app that will be
I am writing an auto update client. It's a very simple app that: 1)
Please consider the simple express.js route: app.get(/test, function(req, res) { if(condition1) { res.render(foo, {
Consider the following case: A web server is running a .NET app with <sessionState
Consider a simple table with an auto-increment column like this: CREATE TABLE foo (
Consider this simple XML document. The serialized XML shown here is the result of
Consider this simple markup: <body> <div style=border: 2px solid navy; position:absolute; width:100%; height:100%> </div>
Consider this simple example (which displays in red): echo -e \033[31mHello World\033[0m It displays

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.