0

I'm using CFEngine to deploy apache sites. So, I have a repository setup and my agents are copying files from it.

The trouble is when I'm editing my files using vim, it creates swap files. And they are copied to the server, which is bad because everytime I'm firing up my editor, all these machines download the swap files.

The big problem is that this triggers the restart of apache.

TLDR: how do I tell CFEngine to ignore files matching \..*\.swp ?

Here's what I have right now:

files:
        "/etc/apache2/sites-available/"
                handle => "apache-sites-available",
                depends_on => { "apacheinstall" },
                create => "true",
                copy_from => secure_cp("/srv/repos/apache2/conf/sites-available/","$(sys.policy_hub)"),
                depth_search => recurse("inf"),
                classes => satisfied("apachemustrestart");
        "/etc/apache2/sites-enabled/"
                handle => "apache-sites-enabled",
                depends_on => { "apacheinstall", "apache-sites-available" },
                create => "true",
                copy_from => secure_cp("/srv/repos/apache2/conf/sites-enabled/","$(sys.policy_hub)"),
                depth_search => recurse("inf"),
                classes => satisfied("apachemustrestart");
                # promise_repaired => { "apachemustrestart" };

services:
        "apache2"
                handle => "apacheenable",
                depends_on => { "apache-sites-enabled" },
                service_policy => "start";

        apachemustrestart::
        "apache2" 
                service_policy => "restart";

Here's the satisfied class

body classes satisfied(x)
{   
      promise_repaired => { "$(x)" };
      # persist_time => "0";
}   

Edit: My post was not precise enough.

moebius_eye
  • 1,103
  • 7
  • 21

2 Answers2

0

I'm not certain about the CFEngine configuration - I haven't worked with that. You can work around your issue by telling vim not to create additional files during editing.

set nobackup

set nowritebackup

set noswapfile

Stuart Smith
  • 228
  • 2
  • 7
  • That would be a last resort option. I'm also trying to find a way to ignore some files because I want to use git to push these files into the `/srv/repos/` directories. – moebius_eye Apr 21 '15 at 13:53
  • I know I can use gitignore to ignore the swap files too. But, regardless, I've been looking for a way to ignore files for some days now. – moebius_eye Apr 21 '15 at 15:35
  • It looks like the old file class had options to symlink, ignore, exclude, and include options. Apparently there was a global ignore directive at one point. Not sure if it was removed or if it's just no longer advertised... http://ftp.gnu.org/old-gnu/Manuals/cfengine/html_node/cfengine-Reference_58.html – Stuart Smith Apr 21 '15 at 16:30
  • You could also probably use a transform to delete the files in question. ( That's my idea of a TRANSFORMATION! ) https://docs.cfengine.com/latest/examples-example-snippets-basic-file-directory.html ( "Locate and transform files" transformer => ) – Stuart Smith Apr 21 '15 at 16:33
0

a bit late, but provided no one has given an answer to this I will:

bundle agent filecache {
    files:
        myclass::
          "/etc/apache2/sites-available/"
            copy_from   => mycopy("/your_path","$(sys.policy_hub)"),
            depth_search => recursive_exc_swp;
}

body copy_from mycopy(from,server) {
      source      => "$(from)";
      servers     => { "$(server)" };
      purge       => "true";
      stealth     => "true";
      preserve    => "true";
}

body depth_search recursive_exc_swp {
    depth => "inf";
    exclude_dirs => { "\.swp" };
}
natxo asenjo
  • 5,739
  • 2
  • 26
  • 27