{"id":506,"date":"2022-09-18T21:04:07","date_gmt":"2023-02-14T04:44:23","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/uncategorized\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/"},"modified":"2024-03-18T15:13:06","modified_gmt":"2024-03-18T15:13:06","slug":"here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/","title":{"rendered":"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04"},"content":{"rendered":"<p>CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all aspects of your infrastructure, including Linux, Mac, Windows, BSD, Solaris, IBM AIX, HP-UX, and various other platforms, using a single tool and policy language. Simply installing a C-written agent on each machine grants you the ability to control and monitor diverse environments. Whether you have a resource-intensive infrastructure or limited Internet of Things (IoT) devices, CFEngine is the ideal choice as it supports numerous platforms and is tailor-made for such scenarios.<\/p>\n<p>You will be guided through the process of installing CFEngine Community Edition 3.21 on Ubuntu 20.04, creating example policy files, and automating your policy executions in this tutorial.<\/p>\n<h2>Requirements<\/h2>\n<p>In order to finish this tutorial, you will require:<\/p>\n<ul class=\"post-ul\">\n<li>One<a href=\"https:\/\/releases.ubuntu.com\/focal\"> Ubuntu 20.04<\/a> server with a non-root sudo user. To set this up, follow our guide Initial Server Setup with Ubuntu 20.04.<\/li>\n<li>A way of running shell commands (including sudo), such as ssh.<\/li>\n<li>A text editor. This tutorial uses nano.<\/li>\n<\/ul>\n<h2>First Step \u2014 CFEngine Installation<\/h2>\n<p>In this stage, you will be able to install CFEngine by utilizing apt along with the package repositories. The key benefit of employing apt for installation purposes is that it allows you to conveniently update CFEngine in the future.<\/p>\n<p>There are alternative methods of installing CFEngine that can cater to various scenarios.<\/p>\n<ul class=\"post-ul\">\n<li>cf-remote is a flexible choice that handles installing on multiple machines, different versions of CFEngine, and nightly builds.<\/li>\n<li>The quick-install shell script is a good choice for a single machine. You can install by copying a single command into the terminal.<\/li>\n<li>You can also download the packages directly from the website.<\/li>\n<\/ul>\n<p>If you choose to use any of these options to install CFEngine Community or Enterprise, you can either proceed to Step 2 and start CFEngine after installing, or go directly to Step 3 and create your first policy after bootstrapping.<\/p>\n<h3>Including the public key of CFEngine<\/h3>\n<p>In order to install CFEngine through apt, apt must have access to the repository. The initial action is to include the CFEngine public GPG key in the apt key collection, ensuring that apt can trust the packages obtained from the repository.<\/p>\n<p>Obtain the key by using this command.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">wget<\/span> https:\/\/cfengine.com\/pub\/gpg.key <span class=\"token parameter variable\">-O<\/span> ~\/cfengine-gpg.key<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>After that, utilize apt-key to include it.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> apt-key <span class=\"token function\">add<\/span> ~\/cfengine-gpg.key<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<h3>Including the Package Repositories offered by CFEngine<\/h3>\n<p>Afterwards, you have to include the CFEngine repository as an apt source by executing the subsequent command:<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">sh<\/span> <span class=\"token parameter variable\">-c<\/span> <span class=\"token string\">&#8220;echo &#8216;deb https:\/\/cfengine-package-repos.s3.amazonaws.com\/pub\/apt\/packages stable main&#8217; &gt; \/etc\/apt\/sources.list.d\/cfengine-community.list&#8221;<\/span><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>This instruction appends the CFEngine repository to a file located in the directory for apt sources list.<\/p>\n<p>If the sh argument and -c option are not included, executing this command would result in a Permission denied error since sudo does not handle the output redirection. To overcome this problem, you can employ sh to run a shell with sudo and pass the command using the -c option.<\/p>\n<p>Go ahead and use the update command which will allow apt to recognize the fresh packages available in the CFEngine repository.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<h3>Installing the Package using apt<\/h3>\n<p>Now that the CFEngine package has been added to the apt registry, you have the option of installing CFEngine using apt.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> cfengine-community<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>You may disregard any warnings regarding the package being developed on an older operating system. It is still functional.<\/p>\n<h3>Confirming the Installation<\/h3>\n<p>After the installation is finished, you can find the CFEngine components in \/var\/cfengine\/bin. Among them, the agent (cf-agent) is the primary one with which you will mainly interact. This executable assesses the policy you create, modifies the system accordingly, and keeps a record of its actions. By default, the agent will activate every five minutes, retrieve any updated policy if needed, and apply it.<\/p>\n<p>Make use of the given command to ensure that the agent has been installed successfully.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> cf-agent <span class=\"token parameter variable\">&#8211;version<\/span><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The screen will display the printed version number.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>CFEngine Core 3.21.0<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>Please note that the current version is 3.21.0 as of now. Your version number might be different.<\/div>\n<\/div>\n<p>If you are unable to run the cf-agent command, make sure to verify if \/var\/cfengine\/bin\/ is included in your PATH variable and if cf-agent exists in that specific directory. Additionally, you can examine the installation log file located at \/var\/log\/CFEngine-Install.log to get some insights into any potential issues that occurred during the installation process.<\/p>\n<h2>Step 2 involves commencing CFEngine.<\/h2>\n<p>To initiate CFEngine, you must bootstrap the agent by executing the provided command.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> cf-agent <span class=\"token parameter variable\">&#8211;bootstrap<\/span> <span class=\"token number\">127.0<\/span>.0.1<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The specified instruction instructs the agent to initiate the CFEngine elements and obtain the policy from this particular device with the IP address 127.0.0.1.<\/p>\n<p>In the coming days, you may need multiple machines to retrieve policy from a shared server. At that time, you will replace the IP address 127.0.0.1 with the actual IP address of the server. However, for now, while you are getting started with CFEngine and learning, you will use just one machine and the IP address 127.0.0.1 as described in this tutorial.<\/p>\n<p>After successfully setting up CFEngine on your server, it&#8217;s time to begin creating your policy.<\/p>\n<h2>Step 3 involves the creation of your initial policy.<\/h2>\n<p>To automate a task in system administration with CFEngine, you&#8217;ll need to generate a policy file. This file is specifically written in CFEngine&#8217;s own Domain Specific Language (DSL). If you want to understand the capabilities and structure of this policy language, refer to the CFEngine reference documentation.<\/p>\n<p>Policy files are different from scripts because they work in a declarative manner. By describing the desired state for the system, CFEngine will evaluate if it is already fulfilled and will only make alterations if required. Instances of what you might want to express in policy include:<\/p>\n<ul class=\"post-ul\">\n<li>Ensure the user sammy exists.<\/li>\n<li>Keep the curl package updated (and installed).<\/li>\n<li>Ensure telnet is not installed.<\/li>\n<li>Render a script file from a template and some data.<\/li>\n<li>Stop a process, like httpd, if it\u2019s running.<\/li>\n<li>Enforce strict permissions on the \/usr\/bin folder.<\/li>\n<\/ul>\n<p>For each of these instances, you need to create a policy and save it in the appropriate location on your server (\/var\/cfengine\/masterfiles). Afterward, CFEngine will execute the policy.<\/p>\n<ul class=\"post-ul\">\n<li>Automate distribution of the policy file by transferring it to your other bootstrapped hosts.<\/li>\n<li>Enforce your requirements regularly (running the policy every five minutes by default). For example, if someone deleted the user sammy, or changed the permissions on \/usr\/bin, these changes would be restored automatically within five minutes.<\/li>\n<li>Only make changes, such as writing to a file, if it\u2019s necessary (that is, if the state is not already as desired).<\/li>\n<li>Handle many platform differences for you (for example, the commands used to install packages, create users, and other operations vary depending on the operating system).<\/li>\n<\/ul>\n<p>In this stage, you will generate a policy called &#8220;Hello World&#8221; that will display the text &#8220;Hello!&#8221; on the terminal.<\/p>\n<p>Create a new file named &#8220;hello_world.cf&#8221; in your home directory using either nano or your preferred text editor.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> ~\/hello_world.cf<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>To the document, include the subsequent information.<\/p>\n<div>&#8220;hello_world.cf&#8221; file in the home directory.<\/div>\n<pre class=\"post-pre\"><code>bundle agent main\r\n{\r\n  reports:\r\n    \"Hello!\";\r\n}\r\n<\/code><\/pre>\n<p>CFEngine policy is not evaluated from top to bottom; rather, it is declarative in nature.<\/p>\n<p>In CFEngine policy language, a promise refers to each statement made about the managed aspect. Organized into bundles, promises offer the flexibility to selectively run different parts of the policy and determine their order of execution.<\/p>\n<p>In this policy, &#8220;reports&#8221; is a type of commitment that is in charge of displaying the message on the terminal. When &#8220;agent&#8221; is mentioned after &#8220;bundle,&#8221; it indicates that this bundle is intended for the cf-agent component. The bundle is named &#8220;main.&#8221; The bundle sequence determines the order in which bundles are assessed. By default, it already includes the main bundle, so there is no need to make any modifications.<\/p>\n<p>To save and exit the file, employ nano and press CTRL+X to exit. Then, press Y to save and ENTER to confirm the filename, ultimately closing the file.<\/p>\n<p>Because CFEngine usually operates as the root user, it aims to prevent unauthorized system alterations by enforcing strict permissions on policy files. Allowing other users to modify the policies that CFEngine uses would grant them the ability to make privileged changes to the system. To prevent this, you can utilize chmod to modify the file permissions and ensure that only specific users are able to edit this file.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">chmod<\/span> <span class=\"token number\">600<\/span> hello_world.cf<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>To execute the policy, employ the subsequent command.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> cf-agent ~\/hello_world.cf<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>The CFEngine agent locates your bundle by recognizing its main name. Subsequently, the agent examines the promises within the bundle and assesses them. During the evaluation of promises, the agent verifies if any system modifications are required. In this scenario, there was only one promise, and the agent concluded that it should display a message on the terminal to fulfill it.<\/p>\n<p>You will get the output as stated below.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>R: Hello!<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>CFEngine has a default setting where it maintains a record of actions performed and avoids reassessing promises that were evaluated recently (within the past minute). If you attempt to execute the policy again, no output will be displayed. To deactivate this locking mechanism, you can utilize the &#8211;no-lock command line option.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> cf-agent &#8211;no-lock hello_world.cf<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>After successfully creating and implementing your initial policy, it appears that it only facilitates console output without modifying the system itself. However, the upcoming phase will involve making those necessary changes.<\/p>\n<h2>Step 4 involves creating a policy to effectively handle the content within a text file.<\/h2>\n<p>In the previous phase, you developed a policy which involved displaying a message on the terminal. Nonetheless, if we consider a more practical scenario, it would be to guarantee the existence of a file with certain content on every host within your infrastructure. In this stage, you will generate a policy that generates a text file (\/tmp\/my_file.txt) containing the words Hello, CFEngine!.<\/p>\n<p>Please create a new policy file at the location ~\/file_management.cf.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">nano<\/span> ~\/file_management.cf<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Include the provided information.<\/p>\n<div>The cf file for managing files in the specified directory.<\/div>\n<pre class=\"post-pre\"><code>bundle agent manage_my_file\r\n{\r\n  files:\r\n    \"\/tmp\/my_file.txt\"\r\n      content =&gt; \"Hello, CFEngine!$(const.n)\";\r\n}\r\n<\/code><\/pre>\n<p>Instead of naming the bundle as &#8220;main&#8221;, it should be called &#8220;manage_my_file&#8221;. It is advisable to assign distinct and meaningful names to each bundle as you continue to write policies. Remember, there can only be a single main bundle.<\/p>\n<p>Since this policy deals with files, it has a promise type of files. For file promises, the attribute content specifies the expected content of the file. The final section of the string, $(const.n), expands the special variable const.n, resulting in the addition of a new line at the file&#8217;s end.<\/p>\n<p>Please save and exit the file.<\/p>\n<p>Just like before, establish the policy file&#8217;s stringent permissions.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">chmod<\/span> <span class=\"token number\">600<\/span> file_management.cf<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Please execute the file while including some extra command line options.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> cf-agent &#8211;no-lock <span class=\"token parameter variable\">&#8211;info<\/span> ~\/file_management.cf <span class=\"token parameter variable\">&#8211;bundle<\/span> manage_my_file<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>In order to manage my file, it is essential to specify the bundle using &#8211;bundle manage_my_file as there is no longer a primary bundle.<\/p>\n<p>When using the &#8211;info option, CFEngine will provide informational notifications regarding the modifications it is implementing on the system.<\/p>\n<p>The changes will be described in the output of this command.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>info: Using command line specified bundlesequence info: Created file &#8216;\/tmp\/my_file.txt&#8217;, mode 0600 info: Updated file &#8216;\/tmp\/my_file.txt&#8217; with content &#8216;Hello, CFEngine!<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>CFEngine successfully generated my_file.txt in the \/tmp folder, containing the message Hello, CFEngine!.<\/p>\n<p>If you execute the same command once more, you will no longer see any notifications regarding the file creation or update. CFEngine understands that the file&#8217;s contents are already accurate and doesn&#8217;t make any alterations.<\/p>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>Note: When creating and testing policy files, it is common to use &#8211;no-lock and &#8211;info together. To simplify the process, shortcuts are available, such as -KI, which is the same as using &#8211;no-lock &#8211;info.<\/div>\n<\/div>\n<p>After creating a functional system policy, you may wish to run it independently without needing your oversight. This will be carried out in the upcoming phase.<\/p>\n<h2>Step 5 involves the automation of policy runs.<\/h2>\n<p>Using CFEngine&#8217;s automation features can save you from the hassle of manually executing policy via the command line constantly.<\/p>\n<p>You can achieve automation of policy runs by placing your policy files in the designated location and making updates to a JSON file. This JSON file will regularly instruct the CFEngine component to perform tasks in the background, eliminating the need for you to manually run commands from the command line.<\/p>\n<p>To copy the policy file you made in the previous step, use the given command and move it to the suggested destination.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">cp<\/span> file_management.cf \/var\/cfengine\/masterfiles\/services\/<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>It is advised to store your custom policy files in the services\/ subdirectory within \/var\/cfengine\/masterfiles\/ in order to keep them distinct from the default CFEngine policy, which includes policy not authored by you.<\/p>\n<p>When the CFEngine agents retrieve new policy files, they duplicate them from this directory on the hub. Even if you are only operating on one machine, the agent operates similarly: it will search for files in \/var\/cfengine\/masterfiles and duplicate them to \/var\/cfengine\/inputs. For beginners, it is advisable to utilize these paths. Modifying the paths or placing policy files in different locations would necessitate additional effort to guarantee that permissions, copying, and file location are all handled accurately.<\/p>\n<p>Afterwards, generate a JSON file that augments the policy file&#8217;s location and specifies the bundle to be executed.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">nano<\/span> \/var\/cfengine\/masterfiles\/def.json<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Include the provided information in that document.<\/p>\n<div>The file def.json is located in the directory \/var\/cfengine\/masterfiles.<\/div>\n<pre class=\"post-pre\"><code><span class=\"token punctuation\">{<\/span>\r\n  <span class=\"token property\">\"inputs\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span> <span class=\"token string\">\"services\/file_management.cf\"<\/span> <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span>\r\n  <span class=\"token property\">\"vars\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span>\r\n    <span class=\"token property\">\"control_common_bundlesequence_end\"<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span> <span class=\"token string\">\"manage_my_file\"<\/span> <span class=\"token punctuation\">]<\/span>\r\n  <span class=\"token punctuation\">}<\/span>\r\n<span class=\"token punctuation\">}<\/span>\r\n<\/code><\/pre>\n<p>To ensure your policy runs regularly (every five minutes), you need to ensure that the agent locates and reads the file and runs your bundle.<\/p>\n<p>The def.json file&#8217;s inputs key informs the agent about which policy files to access. In this scenario, the agent will access the policy file named file_management.cf that you generated in the previous step.<\/p>\n<p>The vars option allows for variable definition. By incorporating the control_common_bundlesequence_end variable in the default policy, any bundle names added there will be assessed after all the default bundles in the bundlesequence. Hence, cf-agent can choose the policy files to read and the bundles within them to evaluate automatically, eliminating the need to specify these details via the command line.<\/p>\n<p>Once you are making changes to the policy within \/var\/cfengine\/masterfiles\/, automation will handle the remaining tasks. In particular, cf-agent will regularly check for the updated policy files that you have written. The agent will read and assess the policy, ensuring all the commitments are enforced and making necessary modifications to the machines, like editing files and creating users.<\/p>\n<p>According to the policy outlined in this tutorial, whenever the agent is executed, it will confirm the existence of \/tmp\/my_file.txt, along with the specific content mentioned in the policy file.<\/p>\n<p>Please save the file and then close it.<\/p>\n<p>To verify the functionality of automation, remove the text file that was generated during the initial execution of the file management policy.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">rm<\/span> \/tmp\/my_file.txt<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>You will be able to verify if CFEngine has successfully regenerated my_file.txt in the background after a five-minute duration.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">cat<\/span> \/tmp\/my_file.txt<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<div class=\"secondary-code-label\" title=\"Output\">Output<\/div>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Hello, CFEngine.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>Instead, you can also choose to expedite the process of creating the file.<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<ol>\n<li data-prefix=\"$\"><span class=\"token function\">sudo<\/span> <span class=\"token function\">rm<\/span> \/tmp\/my_file.txt <span class=\"token punctuation\">;<\/span> <span class=\"token function\">sudo<\/span> cf-agent <span class=\"token parameter variable\">-Kf<\/span> update.cf <span class=\"token punctuation\">;<\/span> <span class=\"token function\">sudo<\/span> cf-agent <span class=\"token parameter variable\">-KI<\/span><\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"post-pre\"><code><\/code><\/pre>\n<p>CFEngine will identify changes required as the file gets deleted using the rm command.<\/p>\n<p>The initial cf-agent command updates the policy file by duplicating it from \/var\/cfengine\/masterfiles to \/var\/cfengine\/inputs.<\/p>\n<p>The final cf-agent command ensures implementation of your policy by searching for the \/tmp\/my_file.txt file and creating or modifying it when needed.<\/p>\n<p>If you run the agent right after deleting the file, cf-agent will indicate that it has created the file. The likelihood of the agent running in the background between these commands is extremely low.<\/p>\n<div class=\"post-conf-note\">\n<p class=\"post-conf-desc\">Note<\/p>\n<div>Please note that the command sudo cf-agent -Kf update.cf ; sudo cf-agent -KI is equivalent to the default command CFEngine executes every five minutes. Thus, running this command should yield the same outcome as waiting for five minutes, assuming CFEngine is functioning correctly. The initial agent run updates the policy, while the second one assesses the policy and implements alterations to the system.<\/div>\n<\/div>\n<p>Once you have reached this stage, you have successfully automated your initial system administration task using CFEngine. Although the current illustration demonstrates the creation and modification of a file, the procedure for any other task would be the same: formulate the policy, place it in the appropriate directory, and subsequently update the def.json file.<\/p>\n<h2>In summary,<\/h2>\n<p>Once CFEngine has been successfully installed and initiated on a solitary server, you can proceed to create your initial policy and configure it to run automatically.<\/p>\n<p>To proceed further, explore the CFEngine official documentation. Take a look at this tutorial which explains how to manage files by creating, modifying, and deleting them.<\/p>\n<p>If you need assistance or have any inquiries, please feel free to post them in the Q&amp;A section of CFEngine&#8217;s GitHub Discussions.<\/p>\n<p>&nbsp;<\/p>\n<p>More tutorials<\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/one-possible-paraphrase-could-besetting-up-a-programming-environment-and-installing-python-3-on-rocky-linux-9\/\" target=\"_blank\" rel=\"noopener\">Python 3 installing on Rocky Linux 9<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/quickstart-guide-for-setting-up-a-new-user-with-sudo-privileges-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noopener\">sudo for new user with privileges on Rocky Linux 8<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/a-guide-on-creating-a-ruby-on-rails-application-on-ubuntu-22-04\/\" target=\"_blank\" rel=\"noopener\">A guide on creating a Ruby on Rails application on Ubuntu 22.04.<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/one-option-for-paraphrasing-the-given-phrase-could-be-different-server-configurations-frequently-used-for-your-web-application\/\" target=\"_blank\" rel=\"noopener\">Server Configurations Frequently Used for Your Web Application<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n<p><a class=\"LinkSuggestion__Link-sc-1gewdgc-4 cLBplk\" href=\"https:\/\/www.silicloud.com\/blog\/nativeness-is-subjective-as-it-depends-on-the-individuals-native-language-however-i-can-offer-a-paraphrase-in-englishstep-by-step-guide-installing-rust-on-ubuntu-20-04\/\" target=\"_blank\" rel=\"noopener\">Step-by-step Guide: Installing Rust on Ubuntu 20.04<span class=\"sc-gswNZR eASTkv\">(Opens in a new browser tab)<\/span><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all aspects of your infrastructure, including Linux, Mac, Windows, BSD, Solaris, IBM AIX, HP-UX, and various other platforms, using a single tool and policy language. Simply installing a C-written agent on each machine grants you the ability [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-506","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04 - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04\" \/>\n<meta property=\"og:description\" content=\"CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-14T04:44:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-18T15:13:06+00:00\" \/>\n<meta name=\"author\" content=\"Emily Johnson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Emily Johnson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/\"},\"author\":{\"name\":\"Emily Johnson\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378\"},\"headline\":\"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04\",\"datePublished\":\"2023-02-14T04:44:23+00:00\",\"dateModified\":\"2024-03-18T15:13:06+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/\"},\"wordCount\":3004,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/\",\"name\":\"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2023-02-14T04:44:23+00:00\",\"dateModified\":\"2024-03-18T15:13:06+00:00\",\"description\":\"CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378\",\"name\":\"Emily Johnson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g\",\"caption\":\"Emily Johnson\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/emilyjohnson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04 - Blog - Silicon Cloud","description":"CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/","og_locale":"en_US","og_type":"article","og_title":"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04","og_description":"CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all","og_url":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2023-02-14T04:44:23+00:00","article_modified_time":"2024-03-18T15:13:06+00:00","author":"Emily Johnson","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Emily Johnson","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/"},"author":{"name":"Emily Johnson","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378"},"headline":"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04","datePublished":"2023-02-14T04:44:23+00:00","dateModified":"2024-03-18T15:13:06+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/"},"wordCount":3004,"commentCount":0,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/","url":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/","name":"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2023-02-14T04:44:23+00:00","dateModified":"2024-03-18T15:13:06+00:00","description":"CFEngine is an adaptable configuration management solution designed for your IT infrastructure. It empowers you to effortlessly manage all","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/here-is-one-optioninstructions-for-installing-and-utilizing-cfengine-community-edition-on-ubuntu-20-04\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Installing and Utilizing CFEngine Community Edition on Ubuntu 20.04"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3b041b19cffc258705478ecfab895378","name":"Emily Johnson","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a5cb4e73d02ab1d79f2dfe919389ff7c1de072baa97686392031c03d858cc358?s=96&d=mm&r=g","caption":"Emily Johnson"},"url":"https:\/\/www.silicloud.com\/blog\/author\/emilyjohnson\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=506"}],"version-history":[{"count":0,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/506\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}