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

  • SEARCH
  • Home
  • 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 7091355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:10:29+00:00 2026-05-28T08:10:29+00:00

I have two different versions of linux/unix each running cfengine3. Is it possible to

  • 0

I have two different versions of linux/unix each running cfengine3. Is it possible to have one promises.cf file I can put on both machines that will copy different files based on what os is on the clients? I have been searching around the internet for a few hours now and have not found anything useful yet.

  • 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-28T08:10:30+00:00Added an answer on May 28, 2026 at 8:10 am

    There are several ways of doing this. At the simplest, you can simply have different files: promises depending on the operating system, for example:

    files:
      ubuntu_10::
        "/etc/hosts"
          copy_from => mycopy("$(repository)/etc.hosts.ubuntu_10");
      suse_9::
        "/etc/hosts"
          copy_from => mycopy("$(repository)/etc.hosts.suse_9");
      redhat_5::
        "/etc/hosts"
          copy_from => mycopy("$(repository)/etc.hosts.redhat_5");
      windows_7::
        "/etc/hosts"
          copy_from => mycopy("$(repository)/etc.hosts.windows_7");
    

    This example can be easily simplified by realizing that the built-in CFEngine variable $(sys.flavor) contains the type and version of the operating system, so we could rewrite this example as follows:

    "/etc/hosts"
        copy_from => mycopy("$(repository)/etc.$(sys.flavor)");
    

    A more flexible way to achieve this task is known in CFEngine terminology as “hierarchical copy.” In this pattern, you specify an arbitrary list of variables by which you want files to be differentiated, and the order in which they should be considered, from most specific to most general. When the copy promise is executed, the most-specific file found will be copied.

    This pattern is very simple to implement:

    # Use single copy for all files
    body agent control
    {
       files_single_copy => { ".*" };
    }
    
    bundle agent test
    {
    vars:
      "suffixes"   slist => { ".$(sys.fqhost)", ".$(sys.uqhost)", ".$(sys.domain)",
                              ".$(sys.flavor)", ".$(sys.ostype)", "" };
    files:
      "/etc/hosts"
        copy_from => local_dcp("$(repository)/etc/hosts$(suffixes)");
    }
    

    As you can see, we are defining a list variable called $(suffixes) that contains the criteria by which we want to differentiate the files. All the variables contained in this list are automatically defined by CFEngine, although you could use any arbitrary CFEngine variables. Then we simply include that variable, as a scalar, in our copy_from parameter. Because CFEngine does automatic list expansion, it will try each variable in turn, executing the copy promise multiple times (one for each value in the list) and copy the first file that exists. For example, for a Linux SuSE 11 machine called superman.justiceleague.com, the @(suffixes) variable will contain the following values:

    { ".superman.justiceleague.com", ".superman", ".justiceleague.com", ".suse_11",
      ".linux", "" }
    

    When the file-copy promise is executed, implicit looping will cause these strings to be appended in sequence to “$(repository)/etc/hosts”, so the following filenames will be attempted in sequence: hosts.superman.justiceleague.com, hosts.justiceleague.com, hosts.suse_11, hosts.linux and hosts. The first one to exist will be copied over /etc/hosts in the client, and the rest will be skipped.

    For this technique to work, we have to enable “single copy” on all the files you want to process. This is a configuration parameter that tells CFEngine to copy each file at most once, ignoring successive copy operations for the same destination file. The files_single_copy parameter in the agent control body specifies a list of regular expressions to match filenames to which single-copy should apply. By setting it to ".*" we match all filenames.

    For hosts that don’t match any of the existing files, the last item on the list (an empty string) will cause the generic hosts file to be copied. Note that the dot for each of the filenames is included in $(suffixes), except for the last element.

    I hope this helps.

    (p.s. and shameless plug: this is taken from my upcoming book, “Learning CFEngine 3“, published by O’Reilly)

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

Sidebar

Related Questions

I have two xsl file each for different type of machines for various unix
I have two different modules that need access to a single file (One will
We have two machines (under discussion) running ClearCase - different versions of ClearCase. Otherwise,
I have a need to reference two different versions of the Sharepoint API dll.
I have php two servers with different versions of php, and am having trouble
How can you have model declarations at two different directories in Django? I have
I have two different versions (Basic and Professional) of my application. I have created
I'm working on trying to have my project automatically build two different versions of
I have two slightly different versions of my VB applications that I would like
I have .NET enterprise application for work with two different versions. A SQL Compact

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.