Forum: CFEngine Help
Subject: fileexists() on remote host
Author: zont1
Link to topic: https://cfengine.com/forum/read.php?3,24026,24026#msg-24026

Hi,

I want to synchronize some system files with cfengine3. I've got few named 
profiles and one default profile with hierarchy as following:
default/etc/inetd.conf
default/etc/sysctl.conf
profile1/etc/inetd.conf
profile2/etc/sysctl.conf

profile1 has it's own version of inetd.conf and sysctl.conf from default, 
profile2 has it's own sysctl.conf and inetd.conf from default.

I try to use "files:" promises to implement this sceme but I can't find 
function/method to check if file exists on remote server.

How can I check if the file exists on the remote host?


For now, I sync all config files for two profiles - profile1 and default and 
then copy/install config from where it exists.


vars:

    profile1::
        "profile" string => "profile1";
    profile2::
        "profile" string => "profile2";

files:
    freebsd::
        "$(g.masterfiles)/$(profile)"
            comment     => "Copy $(profile) config files",
            perms       => mog("0600", "root", "wheel"),
            depth_search => recurse("inf"),
            copy_from   => remote_sync_dcp("$(g.syncfiles)/$(profile)", 
"$(g.policyhost)");

        "$(g.masterfiles)/default"
            comment     => "Copy default config files",
            perms       => mog("0600", "root", "wheel"),
            depth_search => recurse("inf"),
            copy_from   => remote_sync_dcp("$(g.syncfiles)/default", 
"$(g.policyhost)");

        "/etc/inetd.conf"
            comment     => "Install $(this.promiser) file for $(profile)",
            perms       => mog("0644", "root", "wheel"),
            ifvarclass  => 
and(fileexists("$(g.masterfiles)/$(profile)/etc/inetd.conf")),
            copy_from   => 
no_backup_dcp("$(g.masterfiles)/$(profile)/etc/inetd.conf"),
            classes     => if_repaired("reload_inetd");

        "/etc/inetd.conf"
            comment     => "Install $(this.promiser) file for default",
            perms       => mog("0644", "root", "wheel"),
            ifvarclass  => 
not(fileexists("$(g.masterfiles)/$(profile)/etc/inetd.conf")),
            copy_from   => 
no_backup_dcp("$(g.masterfiles)/default/etc/inetd.conf"),
            classes     => if_repaired("reload_inetd");

        "/etc/sysctl.conf"
            comment     => "Copy $(this.promiser) file for $(profile)",
            perms       => mog("0644", "root", "wheel"),
            ifvarclass  => 
and(fileexists("$(g.masterfiles)/$(profile)/etc/sysctl.conf")),
            copy_from   => 
no_backup_dcp("$(g.masterfiles)/$(profile)/etc/sysctl.conf"),
            classes     => if_repaired("start_sysctl");

        "/etc/sysctl.conf"
            comment     => "Copy $(this.promiser) file for default",
            perms       => mog("0644", "root", "wheel"),
            ifvarclass  => 
not(fileexists("$(g.masterfiles)/$(profile)/etc/sysctl.conf")),
            copy_from   => 
no_backup_dcp("$(g.masterfiles)/default/etc/sysctl.conf"),
            classes     => if_repaired("start_sysctl");

...
commands:

    reload_inetd::
        "/etc/rc.d/inetd reload";

    start_sysctl::
        "/etc/rc.d/sysctl start";
...

body copy_from remote_sync_dcp(from, server)
{
    servers     => { "$(server)" };
    source      => "$(from)";
    compare     => "digest";
    purge       => "true";
}




_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to