Forum: Cfengine Help
Subject: Re: 3.0.2 too old?
Author: phnakarin
Link to topic: https://cfengine.com/forum/read.php?3,20392,21223#msg-21223

Quick look through your policy. It seemed to be fine, nothing was wrong but 
cfengine itself. I spotted a weird behaviour of agent normal ordering. It 
should be commands: then files:, not the other way around. 
http://www.cfengine.org/manuals/cf3-reference.html#Agent-normal-ordering

That would explain why there was no match by set_user_field() as there was a 
line rob:.* (rob:.* would be create by useradd I assumed.) I can report to this 
issue to cfengine developers if you'd like.

To make your coding work wonderfully, I suggested using classes to help you 
out. At least, we could create our own workflow to run a command then to edit 
the file.


commands:
  linux::
    "/usr/sbin/useradd $($(user)[$(index)]) -u $($(user)[$(index)])
    -d $($(user)[$(index)]) -s $($(user)[$(index)])
    -c '$($(user)[$(index)])' $(index)"
    ifvarclass => "add_$(index)",
    classes => if_repaired("set_passwd_for_$(index)");

files:
  # This is not conditioned to the add_* classes to always check
  # and reset the passwords if needed.
  linux::
  "/etc/shadow"
    comment => "Setting the password...",
    edit_line => set_user_field("$(index)",2,"$($(user)[$(index)])"),
    ifvarclass => "set_passwd_for_$(index)";


Please correct me, if I was wrong.

Cheers,
--Nakarin

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to