Variables

thierry thunot <[email protected]> Mon, 20 Jan 2025 02:41:15 -0800 (PST)
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
------=_Part_211668_1750949336.1737369675204
Content-Type: multipart/alternative; 
	boundary="----=_Part_211669_48706993.1737369675204"

------=_Part_211669_48706993.1737369675204
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

=20
Hello everyone, I come to you for a problem with a variable name.=20
In fact I use data to edit variable attributes within an unattended-update=
=20
configuration file for debian.=20
To do this I use the definition of variables like this then use the fields=
=20
of the file in a method to give the values =E2=80=8B=E2=80=8Bto the attribu=
tes. they have=20
names such as Unattended-Upgrade::Automatic-Reboot etc...=20
I get an error variable is not legal. How can I solve this problem

bundle agent    mise_a_jour_os
{
###### Mise a jour de securite sur les postes de travail debian linux
###### Pas de reboot automatique a la discretion de l utilisateur voir=20
bundle avertissement_utilisateur_reboot


        vars:
        "prerequis_update_secu"      slist =3D> {"unattended-upgrades",=20
"apt-listchanges"};
#"fichier_reboot_necessaire" string =3D> "/var/run/reboot-required";

####### Configuration des sources de mise a jour
        "conf_unattentedupgrades[upgrades_pc_dev]"             string =3D>=
=20
"/etc/apt/apt.conf.d/50unattended-upgrades";
        "upgrades_pc_dev[Unattended-Upgrade::Allowed-Origins]" string =3D> =
"{
        // Codename based matching:
        // This will follow the migration of a release through different
        // archives (e.g. from testing to stable and later oldstable).
        // Software will be the latest available for the named release,
        // but the Debian release itself will not be automatically upgraded=
.
//      \"origin=3DDebian,codename=3D\${distro_codename}-updates\";
//      \"origin=3DDebian,codename=3D\${distro_codename}-proposed-updates\"=
;
        \"origin=3DDebian,codename=3D\${distro_codename},label=3DDebian\";
       =20
\"origin=3DDebian,codename=3D\${distro_codename},label=3DDebian-Security\";
       =20
\"origin=3DDebian,codename=3D\${distro_codename}-security,label=3DDebian-Se=
curity\";

        // Archive or Suite based matching:
        // Note that this will silently match a different release after
        // migration to the specified archive (e.g. testing becomes the
        // new stable).
//      \"o=3DDebian,a=3Dstable\";
//      \"o=3DDebian,a=3Dstable-updates\";
//      \"o=3DDebian,a=3Dproposed-updates\";
//      \"o=3DDebian Backports,a=3D${distro_codename}-backports,l=3DDebian=
=20
Backports\";
};";=20
        "upgrades_pc_dev[Unattended-Upgrade::Automatic-Reboot]" string =3D>=
=20
"\"false\";";

###### Configuration de la frequence de mise a jour
        "conf_conf_frequence_auto"            string =3D>=20
"/etc/apt/apt.conf.d/20auto-upgrades";
        "auto-upgrade" slist =3D> {"[APT::Periodic::Update-Package-Lists=20
\"1\";","[APT::Periodic::Unattended-Upgrade] \"1\";"};

##### Configuration de l heure des mise a jour
        "repertoire_conf"    string =3D>=20
"/etc/systemd/system/apt-daily-upgrade.timer.d";
        "repertoire_conf_telechargement"    string =3D>=20
"/etc/systemd/system/apt-daily.timer.d";
        "nom_conf_frequence" string =3D> "override.conf";
        "contenu_conf_freq"  string =3D> "[Timer]
OnCalendar=3D
OnCalendar=3D03:00
RandomizedDelaySec=3D0";
"contenu_telecharge" string =3D> "[Timer]
OnCalendar=3D
OnCalendar=3D03:00
RandomizedDelaySec=3D0";
"contenu_telecharge" string =3D> "[Timer]
OnCalendar=3D
OnCalendar=3D01:05
RandomizedDelaySec=3D0";

      methods:
        "upgrades_pc_dev" usebundle       =3D>=20
edit_fichier_conf_param("$(mise_a_jour_os.conf_unattentedupgrades[upgrades_=
pc_dev])","mise_a_jour_os.upgrades_pc_dev","=20
","//"),
                comment =3D> "/?\---------- Configuration des la methode de=
=20
mise a jour de securite";
        "conf_conf_frequence_auto" usebundle =3D>=20
edit_fichier_conf_param("$(mise_a_jour_os.conf_conf_frequence_auto[auto-upg=
rade])","mise_a_jour_os.auto-upgrade","=20
","//"),
                comment =3D> "/?\---------- Configuration frequence de  mis=
e=20
a jour de securite";


}
bundle agent=20
edit_fichier_conf_param(fichier,variables,separateur,delimit_comm)=20
{
# Bundle permettant les fonctions suivantes:
# Modifier une valeur d'un attribu dans un fichier de configuration
# Le s=C3=A9parateur est le caractere qui s=C3=A9pare le champ de sa valeur=
 ex "=20
champ =3D valeur OU champ : valeur OU champ valeur)
# Le delimit_comm est le caract=C3=A8re  li=C3=A9 a la mise en commentaire =
d'une=20
ligne ex # OU ; OU // etc...
# A noter qu'aucun espace n'est inclu entre le champ, le separateur et la=
=20
valeur si un espace est necessaire l'inclure dans le separateur ex " =3D "=
=20
        vars:
        "c_fichier" string =3D> canonify("$(fichier)");

        files:
        "$(fichier)"
                handle =3D> "edit_fichier_conf_param",
                comment =3D> "Mise a jour du fichier ini de $(fichier)",
                edit_line =3D>=20
set_line_based("$(variables)","$(separateur)","\s*$(separateur)\s*", ".*",=
=20
"\s*$(delimit_comm)\s*"),
                #cr=C3=A9e une classe $fichier_ok, $fichier_kept,=20
$fichier_reached, $fichier_denied, $fichier_repaired, $fichier_failed,=20
$fichier_timout selon les cas
                classes =3D> results("namespace","$(c_fichier)");
}

the error :
...
verbose: B: BEGIN bundle mise_a_jour_os
 verbose: B:=20
*****************************************************************
   error: Variable identifier=20
'auto-upgrade[APT::Periodic::Update-Package-Lists]' is not legal
   error: Promise belongs to bundle 'mise_a_jour_os' in file=20
'/var/cfengine/inputs/sys_maj_secu_debian.cf' near line 61
   error: Variable identifier=20
'auto-upgrade[APT::Periodic:::Unattended-Upgrade]' is not legal
   error: Promise belongs to bundle 'mise_a_jour_os' in file=20
'/var/cfengine/inputs/sys_maj_secu_debian.cf' near line 62
......




thank's again for your help!





--=20
You received this message because you are subscribed to the Google Groups "=
help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/help-cfengi=
ne/cbf65ecb-67ce-4b8b-b2d1-6df070fdf69cn%40googlegroups.com.

------=_Part_211669_48706993.1737369675204
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable


<div><div></div></div><div><div><div><div tabindex=3D"0" role=3D"text"><spa=
n style=3D"text-align: left;" dir=3D"ltr"><span lang=3D"en">Hello everyone,
I come to you for a problem with a variable name. <br />In fact I use data =
to edit variable attributes within an unattended-update configuration file =
for debian.
<br />To do this I use the definition of variables like this then use the f=
ields of the file in a method to give the values =E2=80=8B=E2=80=8Bto the a=
ttributes. they have names such as Unattended-Upgrade::Automatic-Reboot etc=
... <br />I get an error variable is not legal. How can I solve this proble=
m<br /><br />bundle agent =C2=A0 =C2=A0mise_a_jour_os<br />{<br />###### Mi=
se a jour de securite sur les postes de travail debian linux<br />###### Pa=
s de reboot automatique a la discretion de l utilisateur voir bundle averti=
ssement_utilisateur_reboot<br /><br /><br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 var=
s:<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "prerequis_update_secu" =C2=A0 =C2=A0 =
=C2=A0slist =3D&gt; {"unattended-upgrades", "apt-listchanges"};<br />#"fich=
ier_reboot_necessaire" string =3D&gt; "/var/run/reboot-required";<br /><br =
/>####### Configuration des sources de mise a jour<br />=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 "conf_unattentedupgrades[upgrades_pc_dev]" =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 string =3D&gt; "/etc/apt/apt.conf.d/50unattended-upgra=
des";<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "upgrades_pc_dev[Unattended-Upgrade:=
:Allowed-Origins]" string =3D&gt; "{<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Co=
dename based matching:<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 // This will follow=
 the migration of a release through different<br />=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 // archives (e.g. from testing to stable and later oldstable).<br />=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 // Software will be the latest available for the n=
amed release,<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 // but the Debian release it=
self will not be automatically upgraded.<br />// =C2=A0 =C2=A0 =C2=A0\"orig=
in=3DDebian,codename=3D\${distro_codename}-updates\";<br />// =C2=A0 =C2=A0=
 =C2=A0\"origin=3DDebian,codename=3D\${distro_codename}-proposed-updates\";=
<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 \"origin=3DDebian,codename=3D\${distro_co=
dename},label=3DDebian\";<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 \"origin=3DDebia=
n,codename=3D\${distro_codename},label=3DDebian-Security\";<br />=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 \"origin=3DDebian,codename=3D\${distro_codename}-security=
,label=3DDebian-Security\";<br /><br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Archi=
ve or Suite based matching:<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 // Note that t=
his will silently match a different release after<br />=C2=A0 =C2=A0 =C2=A0=
 =C2=A0 // migration to the specified archive (e.g. testing becomes the<br =
/>=C2=A0 =C2=A0 =C2=A0 =C2=A0 // new stable).<br />// =C2=A0 =C2=A0 =C2=A0\=
"o=3DDebian,a=3Dstable\";<br />// =C2=A0 =C2=A0 =C2=A0\"o=3DDebian,a=3Dstab=
le-updates\";<br />// =C2=A0 =C2=A0 =C2=A0\"o=3DDebian,a=3Dproposed-updates=
\";<br />// =C2=A0 =C2=A0 =C2=A0\"o=3DDebian Backports,a=3D${distro_codenam=
e}-backports,l=3DDebian Backports\";<br />};"; <br />=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 "upgrades_pc_dev[Unattended-Upgrade::Automatic-Reboot]" string =3D&g=
t; "\"false\";";<br /><br />###### Configuration de la frequence de mise a =
jour<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "conf_conf_frequence_auto" =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0string =3D&gt; "/etc/apt/apt.conf.d/20auto-u=
pgrades";<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "auto-upgrade" slist =3D&gt; {"[=
APT::Periodic::Update-Package-Lists \"1\";","[APT::Periodic::Unattended-Upg=
rade] \"1\";"};<br /><br />##### Configuration de l heure des mise a jour<b=
r />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "repertoire_conf" =C2=A0 =C2=A0string =3D&g=
t; "/etc/systemd/system/apt-daily-upgrade.timer.d";<br />=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 "repertoire_conf_telechargement" =C2=A0 =C2=A0string =3D&gt; "/e=
tc/systemd/system/apt-daily.timer.d";<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "nom=
_conf_frequence" string =3D&gt; "override.conf";<br />=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 "contenu_conf_freq" =C2=A0string =3D&gt; "[Timer]<br />OnCalendar=3D=
<br />OnCalendar=3D03:00<br />RandomizedDelaySec=3D0";<br />"contenu_telech=
arge" string =3D&gt; "[Timer]<br />OnCalendar=3D<br />OnCalendar=3D03:00<br=
 />RandomizedDelaySec=3D0";<br />"contenu_telecharge" string =3D&gt; "[Time=
r]<br />OnCalendar=3D<br />OnCalendar=3D01:05<br />RandomizedDelaySec=3D0";=
<br /><br />=C2=A0 =C2=A0 =C2=A0 methods:<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
"upgrades_pc_dev" usebundle =C2=A0 =C2=A0 =C2=A0 =3D&gt; edit_fichier_conf_=
param("$(mise_a_jour_os.conf_unattentedupgrades[upgrades_pc_dev])","mise_a_=
jour_os.upgrades_pc_dev"," ","//"),<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=
 =C2=A0 =C2=A0 =C2=A0 comment =3D&gt; "/?\---------- Configuration des la m=
ethode de mise a jour de securite";<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "conf_=
conf_frequence_auto" usebundle =3D&gt; edit_fichier_conf_param("$(mise_a_jo=
ur_os.conf_conf_frequence_auto[auto-upgrade])","mise_a_jour_os.auto-upgrade=
"," ","//"),<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 c=
omment =3D&gt; "/?\---------- Configuration frequence de =C2=A0mise a jour =
de securite";<br /><br /><br />}<br />bundle agent edit_fichier_conf_param(=
fichier,variables,separateur,delimit_comm) <br />{<br /># Bundle permettant=
 les fonctions suivantes:<br /># Modifier une valeur d'un attribu dans un f=
ichier de configuration<br /># Le s=C3=A9parateur est le caractere qui s=C3=
=A9pare le champ de sa valeur ex " champ =3D valeur OU champ : valeur OU ch=
amp valeur)<br /># Le delimit_comm est le caract=C3=A8re =C2=A0li=C3=A9 a l=
a mise en commentaire d'une ligne ex # OU ; OU // etc...<br /># A noter qu'=
aucun espace n'est inclu entre le champ, le separateur et la valeur si un e=
space est necessaire l'inclure dans le separateur ex " =3D " <br />=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 vars:<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "c_fichier" str=
ing =3D&gt; canonify("$(fichier)");<br /><br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =
files:<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 "$(fichier)"<br />=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 handle =3D&gt; "edit_fichier_conf_pa=
ram",<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 comment =
=3D&gt; "Mise a jour du fichier ini de $(fichier)",<br />=C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 edit_line =3D&gt; set_line_based("$(=
variables)","$(separateur)","\s*$(separateur)\s*", ".*", "\s*$(delimit_comm=
)\s*"),<br />=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 #cr=C3=
=A9e une classe $fichier_ok, $fichier_kept, $fichier_reached, $fichier_deni=
ed, $fichier_repaired, $fichier_failed, $fichier_timout selon les cas<br />=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 classes =3D&gt; res=
ults("namespace","$(c_fichier)");<br />}<br /><br />the error :<br />...<br=
 />verbose: B: BEGIN bundle mise_a_jour_os<br />=C2=A0verbose: B: *********=
********************************************************<br />=C2=A0 =C2=A0=
error: Variable identifier 'auto-upgrade[APT::Periodic::Update-Package-List=
s]' is not legal<br />=C2=A0 =C2=A0error: Promise belongs to bundle 'mise_a=
_jour_os' in file '/var/cfengine/inputs/sys_maj_secu_debian.cf' near line 6=
1<br />=C2=A0 =C2=A0error: Variable identifier 'auto-upgrade[APT::Periodic:=
::Unattended-Upgrade]' is not legal<br />=C2=A0 =C2=A0error: Promise belong=
s to bundle 'mise_a_jour_os' in file '/var/cfengine/inputs/sys_maj_secu_deb=
ian.cf' near line 62<br />......<br /><br /><br /><br /><br />thank's again=
 for your help!<br /><br /><br /><br /><br /><br /></span></span></div></di=
v></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;help-cfengine&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">help-=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
help-cfengine/cbf65ecb-67ce-4b8b-b2d1-6df070fdf69cn%40googlegroups.com?utm_=
medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/help-=
cfengine/cbf65ecb-67ce-4b8b-b2d1-6df070fdf69cn%40googlegroups.com</a>.<br /=
>

------=_Part_211669_48706993.1737369675204--

------=_Part_211668_1750949336.1737369675204--