Re: Problem with data

"'Nick Anderson' via help-cfengine" <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
Skimmed a little more ...

This smells to me.

,----
| "nom" slist => getindices( $(valeurs) );
| "repos_complet_$(nom)"
|     string =>  "deb [signed-by=/etc/apt/trusted.gpg.d/$(donnees_extraites[$(nom)][nom_clef_brute])] $(donnees_extraites[$(nom)][url_repo])";
`----

`nom' is a /list/ (`mongodb', `elasticsearch', `graylog').

Then you define a single variable for each of those
(`repos_complet_mongodb', `repos_complet_elasticsearch',
`repos_complet_graylog').

You include `$(donnees_extraites[$(nom)][url_repo])' in your string.
`url_repo' is a list/array (in the case of monodb), so it iterates and
the last iterated value is what is stored in your variable.

You can use `with' to do some dynamic munging and `join()' but then you
need to either deal with probing the data to determine if its a string
or list or you need to make all your urls arrays. But, it's not clear to
me what your wanting it to look like when you print it out.


,----
| bundle agent __main__
| {
|        vars:
| 
|        "clef" string => "toto";
| 
|        "parametrage_des_sources" data => '{
|                    "mogodb" : {
|                        "nom_de_la_liste"     : "mogodb.list",
|                        "nom_clef_brute"     : "GPG-KEY-mongodb.gpg.key",
|                        "nom_clef_signee"     : "GPG-KEY-mongodb.gpg",
|                        "url_repo"           : [
|                                                "http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main",
|                                                "http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main #####TOTOTOTOTO#####"
|                                                ]
|                    },
|                    "elasticsearch" : {
|                        "nom_de_la_liste"     : "elasticsearch.list",
|                        "nom_clef_brute"     : "GPG-KEY-elasticsearch.gpg.key",
|                        "nom_clef_signee"     : "GPG-KEY-elasticsearch.gpg",
|                        "url_repo"           : [ "https://artifacts.elastic.co/packages/oss-7.x/apt stable main" ]
|                    },
|                    "graylog" : {
|                        "nom_de_la_liste"     : "graylog.list",
|                        "nom_clef_brute"     : "graylog-keyring.gpg.key",
|                        "nom_clef_signee"     : "graylog-keyring.gpg",
|                        "url_repo"           : [ "https://packages.graylog2.org/repo/debian/ stable 4.2" ]
|                    }
|                      }'
| 
|                ;
| 
|        methods:
|                "" usebundle => donnees(storejson(parametrage_des_sources));
| 
| }
| bundle agent donnees(valeurs)
| {
|  vars:
|    "donnees_store" string => storejson( $(valeurs) );
|    "donnees_extraites" data => parsejson( $(valeurs) );
|    "nom" slist => getindices( $(valeurs) );
|   #"repos_complet_$(nom)" string =>  "deb [signed-by=/etc/apt/trusted.gpg.d/$(donnees_extraites[$(nom)][nom_clef_brute])] $(donnees_extraites[$(nom)][url_repo])";
|   "repos_complet_$(nom)"
| #      string =>  "deb [signed-by=/etc/apt/trusted.gpg.d/$(donnees_extraites[$(nom)][nom_clef_brute])] $(donnees_extraites[$(nom)][url_repo])";
|        slist =>  maplist( "deb [signed-by=/etc/apt/trusted.gpg.d/$(donnees_extraites[$(nom)][nom_clef_brute])] $(this)", "@(donnees_extraites[$(nom)][url_repo])" );
| 
|  files:
| 
|       #"/root/apt/$(donnees_extraites[$(nom)][nom_de_la_liste])"
|       "/tmp/$(donnees_extraites[$(nom)][nom_de_la_liste])"
|        create => "true",
|        edit_line => append_if_no_line("$(donnees_extraites[$(nom)][url_repo])");
| 
|  reports:
| 
| #"parsejson $(donnees_store)";
|        "parsejson $(donnees_extraites)";
|        "Nom des datas $(nom)";
|        "Nom_de_la_liste pour l'entre '$(nom)' est  : $(donnees_extraites[$(nom)][nom_clef_brute])
|                        l'adresse est $(donnees_extraites[$(nom)][url_repo])
|                        le fichier est $(donnees_extraites[$(nom)][nom_de_la_liste])
|                        le nom de l'url formatee $(with)"
|          with => join( ", ", "repos_complet_$(nom)" );
|        "*****************************
|        deb [signed-by=/etc/apt/trusted.gpg.d/$(donnees_extraites[$(nom)][nom_clef_brute])] $(donnees_extraites[$(nom)][url_repo])";
| 
| }
| bundle edit_line append_if_no_line(lines)
| # @brief Alias for `lines_present`
| # @param lines List or string that should be present in the file
| {
|  insert_lines:
| 
|      "$(lines)"
|        comment => "Append lines if they don't exist";
| }
| 
| 
| body edit_defaults empty
| # @brief Empty the file before editing
| #
| # No backup is made
| {
|      empty_file_before_editing => "true";
|      edit_backup => "false";
|      #max_file_size => "300000";
| }
`----
Listing 1: Example Policy

,----
| R: Nom des datas elasticsearch
| R: Nom des datas graylog
| R: Nom des datas mogodb
| R: Nom_de_la_liste pour l'entre 'elasticsearch' est  : GPG-KEY-elasticsearch.gpg.key
|                        l'adresse est https://artifacts.elastic.co/packages/oss-7.x/apt stable main
|                        le fichier est elasticsearch.list
|                        le nom de l'url formatee deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-elasticsearch.gpg.key] https://artifacts.elastic.co/packages/oss-7.x/apt stable main
| R: Nom_de_la_liste pour l'entre 'graylog' est  : graylog-keyring.gpg.key
|                        l'adresse est https://packages.graylog2.org/repo/debian/ stable 4.2
|                        le fichier est graylog.list
|                        le nom de l'url formatee deb [signed-by=/etc/apt/trusted.gpg.d/graylog-keyring.gpg.key] https://packages.graylog2.org/repo/debian/ stable 4.2
| R: Nom_de_la_liste pour l'entre 'mogodb' est  : GPG-KEY-mongodb.gpg.key
|                        l'adresse est http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main
|                        le fichier est mogodb.list
|                        le nom de l'url formatee deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-mongodb.gpg.key] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main, deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-mongodb.gpg.key] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main #####TOTOTOTOTO#####
| R: Nom_de_la_liste pour l'entre 'mogodb' est  : GPG-KEY-mongodb.gpg.key
|                        l'adresse est http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main #####TOTOTOTOTO#####
|                        le fichier est mogodb.list
|                        le nom de l'url formatee deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-mongodb.gpg.key] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main, deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-mongodb.gpg.key] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main #####TOTOTOTOTO#####
| R: *****************************
|        deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-elasticsearch.gpg.key] https://artifacts.elastic.co/packages/oss-7.x/apt stable main
| R: *****************************
|        deb [signed-by=/etc/apt/trusted.gpg.d/graylog-keyring.gpg.key] https://packages.graylog2.org/repo/debian/ stable 4.2
| R: *****************************
|        deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-mongodb.gpg.key] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main
| R: *****************************
|        deb [signed-by=/etc/apt/trusted.gpg.d/GPG-KEY-mongodb.gpg.key] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main #####TOTOTOTOTO#####
`----

-- 
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 email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/87y1xdajm0.fsf%40northern.tech.

-- 
Nick Anderson | Doer of Things | (+1) 785-550-1767 | https://northern.tech

-- 
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 email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/87y1xdajm0.fsf%40northern.tech.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.