Skip to content

Commit

Permalink
feat/ansible_pb: Add IncludeRole implments 'ITask' in pkg/util/ansiblev2
Browse files Browse the repository at this point in the history
  • Loading branch information
rainzm committed May 9, 2020
1 parent 331ba9b commit faf3241
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/util/ansiblev2/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ func (t *ShellTask) MarshalYAML() (interface{}, error) {
return r, nil
}

type IncludeRole struct {
Name string
Tags []string
Vars map[string]interface{}
When string
}

func (r *IncludeRole) MarshalYAML() (interface{}, error) {
out := map[string]interface{}{
"include_role": map[string]interface{}{"name": r.Name},
}
if len(r.Tags) > 0 {
out["tags"] = r.Tags
}
if len(r.Vars) > 0 {
out["vars"] = r.Vars
}
if len(r.When) > 0 {
out["when"] = r.When
}
return out, nil
}

type Block struct {
Name string
WithPlugin string
Expand Down
8 changes: 8 additions & 0 deletions pkg/util/ansiblev2/playbook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ func TestPlaybookString(t *testing.T) {
"group": "root",
},
},
&IncludeRole{
Name: "foo_app_instance",
Vars: map[string]interface{}{
"dir": "/opt/a",
},
Tags: []string{"bar", "baz"},
When: "ansible_facts['os_family'] == 'RedHat'",
},
)
play.Hosts = "all"
configureBlock := NewBlock(
Expand Down

0 comments on commit faf3241

Please sign in to comment.