Skip to content

How to grab all classes defined from command line? #4520

Answered by olehermanse
craigcomstock asked this question in Q&A
Discussion options

You must be logged in to vote

You want them in an slist, right?

You can use the tag in classesmatching (including the = part):

$ cat test.cf
bundle agent __main__
{
  vars:
    "cmd_line_classes"
      slist => sort(classesmatching(".*", "source=environment"));
  reports:
    "The classes: $(with)"
      with => join(", ", cmd_line_classes);
}
$ /var/cfengine/bin/cf-agent -KI test.cf -Dfoo,bar,baz
R: The classes: bar, baz, foo

(I don't think it's possible to preserve the ordering from the command line, but I guess that doesn't matter).

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@craigcomstock
Comment options

Answer selected by craigcomstock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants