1

I am trying to copy a file using cf-engine from policy hub to host. Empty file is created on the host. How do I get to write the contents? Should policy hub and hosts have the file in same location?

Kiran
  • 23
  • 3
  • Can you post the policy you've been trying to use for copying file? – codewarrior Aug 05 '15 at 12:03
  • I have used a similar policy as listed below. The issue was the directory on server was not opened Up. I moved the file to masterfiles directory and it worked. Thanks for your time codewarrior!!! – Kiran Aug 05 '15 at 17:45

1 Answers1

3

In order to copy a file from a cfengine server needs to have an acl that allows the file to be shared to the remote agent. You can see some examples of access promises in the Masterfiles Policy Frameworks bundle server access_rules.

As a simple example say you want all hosts to share /tmp on the policy hub to all other hosts.

bundle server kiran_access_rules
{
  access:
    # First you restrict promises to the proper context
    # by using a class guard. Here we allow only hosts
    # with the class am_policy_hub or policy_server to
    # share /tmp

    am_policy_hub|policy_server::

      "/tmp"
        admit => { "0.0.0.0/0" }, 
        comment => "Probably you would reference a list in 
                    the admit attribute like @(def.acl).
                    That's the variable named acl in the
                    bundle named def.";
}

And then separately you would have a bundle that promised to copy the file.

bundle agent kirians_bundle
{
  files:
    "/tmp/myfile"
      copy_from => remote_dcp("/tmp/serverfile",$(sys.policy_hub)),
      create => "true";
}

Now, what you see above in this copy_from promise is really multiple promises compressed into one. You are promising that the file exists, and you are promising that the file should have the same content as the file shared by the policy hub. As cfengine converged it was able to repair part but not all of the compound promise. I believe that is why you ended up with an empty file.

Also the best place to ask cfengine questions is on the cfengine help list or in the cfengine IRC channel.

Nick Anderson
  • 296
  • 1
  • 3
  • Thank you Nick. I moved the file location on server to /masterfiles and file got copied to host. Might not be the correct location for the file but you helped me find the root cause. Appreciate it!!! – Kiran Aug 05 '15 at 17:43
  • Glad I could help. Good luck! Please let us know if you need any more help. – Nick Anderson Aug 05 '15 at 19:14