variable are not expanded in handle string

21 views
Skip to first unread message

Xander Cage

unread,
May 17, 2021, 8:09:12 AM5/17/21
to help-cfengine

hey,
while reworking a lot of old policies the following came up...

standalone test policy:

body file control
{
  inputs => { "$(sys.libdir)/stdlib.cf",
            };
}

bundle agent global_env

  {
    vars:

         "d" data => '{
                       "PATH": "/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java8_64/jre/bin:/opt/freeware/bin:/opt/freeware/sbin:."
                       }';


        # map is KEY=VAL
        "name" slist => getindices( d );
        "etcenv[$(name)]" string => "$(d[$(name)])";
        "etcprofile[export $(name)]" string => "$(d[$(name)])";



    files:

        "/etc/environment"
          edit_line => set_line_based("global_env.etcenv", "=", "\s*=\s*", ".*", "\s*#\s*"),
          create => "false",
          handle => "aix_global_env_etc_environment_$(name)_$(d[$(name)])",
          classes => results( "bundle", "_butthurt_classes_expansion_$(this.promiser)_$(this.handle)");

        "/etc/profile"
          edit_line => set_line_based("global_env.etcprofile", "=", "\s*=\s*", ".*", "\s*#\s*"),
          create => "false",
          handle => "aix_global_env_etc_profile_$(name)_$(d[$(name)])",
          classes => results( "bundle", "_butthurt_classes_expansion_$(this.promiser)_$(this.handle)");

    reports:
        "CFEngine $(sys.cf_version)";
        "etcenv[$(name)] contains $(d[$(name)])";
        "etcprofile[export $(name)] contains $(d[$(name)])";
        "Classes defined as result of files promise :$(const.n)$(const.t)$(with)"
        with => join( "$(const.n)$(const.t)", classesmatching( "_butthurt_classes_expansion.*" ) );
  }

bundle agent __main__
{
  methods: "global_env";
}

output:

root@aixtest01: /root/cfe_testbed # /var/cfengine/bin/cf-agent -KI -f ./aix_global_env.cf
R: CFEngine 3.15.3
R: etcenv[PATH] contains /usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java8_64/jre/bin:/opt/freeware/bin:/opt/freeware/sbin:.
R: etcprofile[export PATH] contains /usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java8_64/jre/bin:/opt/freeware/bin:/opt/freeware/sbin:.
R: Classes defined as result of files promise :
        _butthurt_classes_expansion__etc_profile_aix_global_env_etc_profile___name____d___name____kept
        _butthurt_classes_expansion__etc_profile_aix_global_env_etc_profile___name____d___name____reached
        _butthurt_classes_expansion__etc_environment_ aix_global_env_etc_environment___name____d___name____kept
        _butthurt_classes_expansion__etc_environment_aix_global_env_etc_environment___name____d___name____reached

it produces "unexpanded" variable content. this is not a problem per se, the promsies are functional, but as i am doing file reporting, these string are a little bit distracting.
i guess this has something to do with the handles content gets overwritten/cleared out in the reporting loop, but i would not go and build houses on this idea.

wbr

chris

Nick Anderson

unread,
May 17, 2021, 11:47:48 AM5/17/21
to Xander Cage, help-cfengine

Xander Cage <christia...@itsv.at> writes:

_butthurt_classes_expansion__etc_environment_aix_global_env_etc_environment___name____d___name____reached

it produces "unexpanded" variable content. this is not a problem per se, the promsies are functional, but as i am doing file reporting, these string are a little bit distracting. i guess this has something to do with the handles content gets overwritten/cleared out in the reporting loop, but i would not go and build houses on this idea.

Looks like a good candidate for a bug report.

It's very helpful when you can include a minimal reproducer. I kind of suspect that this is related to this.promiser and this.handle being used in classes bodies specific to files promises since I can define classes containing this.promiser and this.handle using commands promises

bundle agent __main__
{
  vars:

    "something" string => "in a var";

  commands:  
      "/bin/echo Test Commands 0" 
        handle => "command_0_static_promiser_static_handle",  
        classes => results( "namespace", "command_0_/bin/echo Test Commands 0_command_0_static_promiser_static_handle" );


      "/bin/echo Test Commands 1" 
        handle => "command_1_static_promiser_static_handle",  
        classes => results( "namespace", "command_1_$(this.promiser)_$(this.handle)" );

      "/bin/echo Test Commands 2 $(something)" 
        handle => "command_2_dynamic_promiser_dynamic_handle_$(something)",  
        classes => results( "namespace", "command_2_$(this.promiser)_$(this.handle)" );


}
# cf-agent --no-lock --log-level info --show-evaluated-classes=command_ --file /tmp/commands-promise-classes-containing-this-promiser-and-this-handle.cf
    info: Executing 'no timeout' ... '/bin/echo Test Commands 0'
  notice: Q: ".../bin/echo Test ": Test Commands 0
    info: Last 1 quoted lines were generated by promiser '/bin/echo Test Commands 0'
    info: Completed execution of '/bin/echo Test Commands 0'
    info: Executing 'no timeout' ... '/bin/echo Test Commands 1'
  notice: Q: ".../bin/echo Test ": Test Commands 1
    info: Last 1 quoted lines were generated by promiser '/bin/echo Test Commands 1'
    info: Completed execution of '/bin/echo Test Commands 1'
    info: Executing 'no timeout' ... '/bin/echo Test Commands 2 in a var'
  notice: Q: ".../bin/echo Test ": Test Commands 2 in a var
    info: Last 1 quoted lines were generated by promiser '/bin/echo Test Commands 2 in a var'
    info: Completed execution of '/bin/echo Test Commands 2 in a var'
Class name                                                   Meta tags                               
command_0__bin_echo_Test_Commands_0_command_0_static_promiser_static_handle_reached                                         
command_0__bin_echo_Test_Commands_0_command_0_static_promiser_static_handle_repaired                                         
command_1__bin_echo_Test_Commands_1_command_1_static_promiser_static_handle_reached                                         
command_1__bin_echo_Test_Commands_1_command_1_static_promiser_static_handle_repaired                                         
command_2__bin_echo_Test_Commands_2_in_a_var_command_2_dynamic_promiser_dynamic_handle_in_a_var_reached                                         
command_2__bin_echo_Test_Commands_2_in_a_var_command_2_dynamic_promiser_dynamic_handle_in_a_var_repaired                                         

Xander Cage

unread,
May 18, 2021, 2:51:17 AM5/18/21
to help-cfengine

Nick Anderson

unread,
May 18, 2021, 2:08:15 PM5/18/21
to help-cfengine
Thanks!
Reply all
Reply to author
Forward
0 new messages