Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to RUDDER Language

7d9785e3bdceb2d9e86dabcfb77b1686?s=47 Rudder
February 04, 2020

Introduction to RUDDER Language

🎥 https://www.youtube.com/watch?v=A6klC0dwjhU
🧑 Benoît Peccate
📅 Configuration Management Camp 2020

RUDDER is a graphical configuration management tool, which is quite an unusual approach in this domain. This talk is about the why and how we are now introducing a new DSL for RUDDER. If you had never considered RUDDER because he didn't have a DSL, or if you want to discuss language with us, now is the right time to attend this talk!

7d9785e3bdceb2d9e86dabcfb77b1686?s=128

Rudder

February 04, 2020
Tweet

Transcript

  1. RUDDER Language What ? Why ? CONTINUOUS AUDITING & CONFIGURATION

  2. A new language ! Why ? 2

  3. Why ? More than one engine ▪ We currently support

    CFEngine ▪ We currently support DSC ▪ We want more (mgmt ? puppet ? ansible ?) 3
  4. Why ? Less code ? ▪ NCF doesn’t map directly

    to CFEngine and DSC ▪ We need a lot of extra code to make it NCF ▪ We could put this code into a generator 4
  5. Why ? New features ▪ NCF contains a lot of

    methods ▪ Adding a single feature may require to touch each one a. Ex: change logging ▪ We could add the feature quickly in the generator 5
  6. Why ? New features 6 F1 F2 F3 F4 M1

    x x x x M2 x x x x M3 x x x x F1 F2 F3 F4 M1 M2 M3 Compiler x x x x x x x
  7. Why ? Higher level language ▪ Be more descriptive ▪

    Be less prescriptive (less logic) ▪ Be more expressive (less code) 7
  8. Why ? Compiler ▪ Be stricter ▪ Have compile time

    errors ▪ Have higher level checks ▪ Have type checking 8
  9. Why ? Compiler 9 Code Agent User Feedback Code Agent

    User Feedback Compiler
  10. Why ? Existing languages ▪ Compile time warning and errors

    - Be strict ▪ Separate compiler from interpreter ▪ We can add things to the language through the compiler ▪ Do not depend on the quirks of a given agent 10
  11. Why ? New DSL ! ▪ Yes and ▪ It’s

    better than poor data format ▪ Everyone should have his own DSL 11
  12. A new language ! How ? 12

  13. How ? Define a language ▪ Concepts ▪ Syntax ▪

    Document design decisions ▪ Try to rewrite existing code 13
  14. How ? Build a compiler ▪ In rust we trust

    ▪ Parse with nom ▪ Create new language structure in memory ▪ Check for sanity ▪ Generate for target engine language 14
  15. How ? Build a compiler ▪ Nom ▪ Parser combinator

    ▪ Easy development of parser ▪ Less easy error reporting 15
  16. How ? Nom Separator Word Delimited List of words Regex

  17. How ? Build a translator ▪ To transparently keep existing

    code ▪ In rust we trust ▪ Convert to json and read this ▪ Convert what is obvious ▪ Have heuristics and guesses for new concepts ▪ Fail in case we don’t know and let the user fix it 17
  18. How ? Integrate it transparently ▪ Have the translator and

    compiler work in parallel with existing editor ▪ Make them report error when they see some ▪ Do not block the user ▪ When ready, translate existing code and start from there 18
  19. A new language ! What ? 19

  20. What ? First aim for techniques ▪ We want the

    language to be everywhere ▪ But let’s be incremental ▪ Target a language subset for creating techniques ▪ Nothing really new 20
  21. What ? Now the boring stuff 21

  22. What ? Language concepts ▪ The resource ▪ Identified by

    parameters ▪ No parameter means it is single instance ▪ Identical instance parameter mean instance equality 22
  23. What ? Language concepts ▪ The state ▪ Applies on

    a resource ▪ Specified by parameters ▪ Either of a ‘present’ kind or ‘absent’ ▪ States are mutually exclusive except identical states 23
  24. What ? Example 24 resource File(path) File state content(bytes) {

    ... } resource OpenNTP() OpenNTP state configured() { File(“/etc/ntpd.conf”).content(“blah”) }
  25. What ? Language concepts ▪ The universe ▪ The only

    resource that is automatically instantiated with a state ▪ Has a main state that you must define 25
  26. What ? Language concepts ▪ Metadata ▪ Just key /

    values ▪ Starts with a ‘@’ ▪ Does not change the language ▪ Change how things are compiled for a given target 26
  27. What ? Technique metadata example 27 @name="Configure NTP" @description="NTP test

    technique" @version="1.0" @parameters=[ “server_name ]
  28. What ? Language concepts ▪ Classic types: dict, array, string,

    integer, boolean ▪ A parameter can have a type and a default value ▪ Default type is “string” ▪ Or detected from default value 28
  29. What ? Language concepts ▪ Type: dict ▪ A JSON

    like object - dict in python - Hashmap - ... 29
  30. What ? Type example 30 function1() function2(a:integer, b=”default”) function3(a:integer, b)

    function4(a = { “key”:”default value”})
  31. What ? Language concepts ▪ Type: Enum ▪ One of

    many (C / rust enum without data) ▪ Can be inferred from other enum ▪ Ex: we can infer a. debian from debian-9 b. OK from success 31
  32. What ? Enum example 32 enum outcome { kept, repaired,

    error } global enum os { ubuntu, debian } enum os ~> family { ubuntu -> debian, debian -> debian }
  33. What ? Language concepts ▪ Case: Enum ▪ We can

    check that all cases are handled ▪ A case must have all cases or a default ▪ Accept complex boolean expression base on enum ▪ Having a default that does nothing is acceptable as long as it is explicit 33
  34. What ? Enum example 34 case { ubuntu => File("/tmp").permissions("root",

    "root", "g+w"), os:debian | centos => File("/tmp").permissions("user", "user", "g+w") default => error(“BUG”) } case { outvar =~ repaired => log(“repaired”) default => noop }
  35. What ? Mapping with existing concepts ▪ Generic method :

    state (all … until next step) ▪ Method category : resource ▪ Technique : resource with a state ▪ Outcome, conditions, classes : enum ▪ Hardclasses : global enum ▪ Report component : metadata 35
  36. What ? Full technique example 36 @format=0 @name="Configure NTP" @description="test"

    @version="1.0" @parameters=[] resource Configure_NTP() Configure_NTP state technique() { @component = "Package present" package("ntp").present() as ntp_present }
  37. A new language ! When ? 37

  38. When ? First release when it’s ready ▪ Rudder 6.1

    ▪ But let’s be incremental ▪ Target a language subset to create techniques 38
  39. When ? Can still be changed ▪ Language definition still

    open ▪ First version is for testing applicability ▪ Your input can improve things 39
  40. When ? Next, target the rest ▪ Generic methods writing

    in rudder-lang ▪ Everything in rudder-lang ? ▪ New language elements ▪ Key value store ? 40
  41. When ? Language concepts ▪ Function ▪ Takes an input

    and gives matching output ▪ Output for a given input should not change ▪ Can be a combination of functions 41
  42. When ? Language concepts ▪ Measure ▪ Do not modify

    a resource ▪ Get information that may change or not ▪ Can be a combination of measures and functions 42
  43. When ? Language concepts ▪ Action ▪ Modifies the state

    of a resource ▪ Can be a combinations of actions, functions, and measures 43
  44. When ? Language concepts ▪ State ▪ Define a resource

    state ▪ Do not change things that don’t need ▪ Update things that need ▪ Can be a combination of states and functions 44
  45. When ? Language concepts ▪ Unsafe ▪ Allows things that

    should not usually be allowed ▪ Allows an action to be used in a state a. Ex: restart a service after a file change ▪ Allows an external command to be used in a measure a. Ex: shell command 45
  46. When ? Language concepts ▪ Iteration ▪ Iterate over a

    list ▪ Explicitly 46
  47. When ? Language concepts ▪ Templating ▪ Integrate template parsing

    in the language ▪ Detect template error and missing variables at compile time 47
  48. Questions ? 48