Skip to content

Instantly share code, notes, and snippets.

@mpdehaan
Last active November 22, 2018 12:25
Show Gist options
  • Select an option

  • Save mpdehaan/87d0ea05ed11a9b723d555a566d27ee3 to your computer and use it in GitHub Desktop.

Select an option

Save mpdehaan/87d0ea05ed11a9b723d555a566d27ee3 to your computer and use it in GitHub Desktop.

Revisions

  1. mpdehaan revised this gist Nov 22, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,12 @@ class FooRole(Foo):
    def set_bundles(self):
    return [ "ext/foo.yml" ]

    def set_resources(self):
    # you can still add resources the normal way, they will come before before bundle

    def set_handlers(self):
    # same

    =============
    # ext/foo.yml

  2. mpdehaan revised this gist Nov 22, 2018. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -7,11 +7,8 @@

    class FooRole(Foo):

    def set_resources(self)
    return Resources().add_bundle(resources="ext/foo.yml")

    def set_handlers(self):
    return Handlers().add_bundle(handlers="ext/foo.yml")
    def set_bundles(self):
    return [ "ext/foo.yml" ]

    =============
    # ext/foo.yml
  3. mpdehaan revised this gist Nov 22, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -25,11 +25,11 @@ resources:
    - File:
    name: "/etc/motd"
    from_template: "templates/motd.j2"
    mode: "Eval(mode)" # just to show we can load variables, but we still need to be explicit.
    mode__eval: "mode" # just to show we can load variables, but we still need to be explicit.
    signals: "spork"
    - Echo:
    msg: "hello {{ x }}, sometimes"
    when: "Chaos.random() > 2.5"
    when__eval: "Chaos.random() > 2.5"
    handlers:
    - Echo:
    msg: "foo"
  4. mpdehaan revised this gist Nov 22, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -5,12 +5,12 @@

    # ==================

    class FooRole(Foo)
    class FooRole(Foo):

    def resources(self)
    def set_resources(self)
    return Resources().add_bundle(resources="ext/foo.yml")

    def handlers(self):
    def set_handlers(self):
    return Handlers().add_bundle(handlers="ext/foo.yml")

    =============
  5. mpdehaan revised this gist Nov 22, 2018. 1 changed file with 9 additions and 4 deletions.
    13 changes: 9 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -21,13 +21,14 @@ search_path:
    resources:
    - Set:
    mode: 0770
    x: 4567
    - File:
    name: /etc/motd
    from_file: blarg
    mode: "Eval(mode)"
    name: "/etc/motd"
    from_template: "templates/motd.j2"
    mode: "Eval(mode)" # just to show we can load variables, but we still need to be explicit.
    signals: "spork"
    - Echo:
    msg: "hello {{ x }}"
    msg: "hello {{ x }}, sometimes"
    when: "Chaos.random() > 2.5"
    handlers:
    - Echo:
    @@ -43,5 +44,9 @@ if you want any variables you need to Eval()

    implementation: reads YAML file, dynamically returns resources from it.

    you could still mix bundle files with regular python resources, even in the same role.





  6. mpdehaan revised this gist Nov 22, 2018. 1 changed file with 26 additions and 5 deletions.
    31 changes: 26 additions & 5 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,47 @@
    # I don't know about this?
    # most people should prefer the Python DSL
    # but what if some teams don't want to learn Python?
    # here's an OPTIONAL idea for a new capability

    # ==================

    class FooRole(Foo)

    def resources(self)
    return Resources().add_bundle(resources="ext/foo.yml")

    def handlers(self):
    return Resources().add_bundle(handlers="ext/foo.yml")
    return Handlers().add_bundle(handlers="ext/foo.yml")

    =============
    # ext/foo.yml

    Resources:
    search_path:
    - opsmop.core.types
    resources:
    - Set:
    mode: 0770
    - File:
    name: /etc/motd
    from_file: blarg
    mode: "Eval(mode)"
    signals: "spork"
    - Echo:
    msg: "hello {{ xyz }}"
    msg: "hello {{ x }}"
    when: "Chaos.random() > 2.5"
    Handlers:
    handlers:
    - Echo:
    msg: "foo"
    handles: "spork"


    =========
    if I do this, this would clearly be a second class citizen to the main behaviors

    limitations: when always results in an Eval()

    if you want any variables you need to Eval()

    implementation: reads YAML file, dynamically returns resources from it.



  7. mpdehaan created this gist Nov 21, 2018.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    # I don't know about this?

    class FooRole(Foo)

    def resources(self)
    return Resources().add_bundle(resources="ext/foo.yml")

    def handlers(self):
    return Resources().add_bundle(handlers="ext/foo.yml")

    =============

    Resources:
    - File:
    name: /etc/motd
    from_file: blarg
    signals: "spork"
    - Echo:
    msg: "hello {{ xyz }}"
    when: "Chaos.random() > 2.5"
    Handlers:
    - Echo:
    msg: "foo"
    handles: "spork"