-
Notifications
You must be signed in to change notification settings - Fork 198
/
raw_ansible_task.go
172 lines (155 loc) · 4.05 KB
/
raw_ansible_task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package config
import (
"fmt"
"gopkg.in/yaml.v2"
)
type rawAnsibleTask struct {
Block []rawAnsibleTask `yaml:"block,omitempty"`
Rescue []rawAnsibleTask `yaml:"rescue,omitempty"`
Always []rawAnsibleTask `yaml:"always,omitempty"`
Fields map[string]interface{} `yaml:",inline"`
rawAnsible *rawAnsible `yaml:"-"` // parent
}
func (c *rawAnsibleTask) UnmarshalYAML(unmarshal func(interface{}) error) error {
if parent, ok := parentStack.Peek().(*rawAnsible); ok {
c.rawAnsible = parent
} else if parent, ok := parentStack.Peek().(*rawAnsibleTask); ok {
c.rawAnsible = parent.rawAnsible
}
parentStack.Push(c)
type plain rawAnsibleTask
err := unmarshal((*plain)(c))
parentStack.Pop()
if err != nil {
return err
}
if !c.blockDefined() {
check := false
for _, supportedModule := range supportedModules() {
if c.Fields[supportedModule] != nil {
if check {
return newDetailedConfigError("invalid ansible task!", c, c.rawAnsible.rawImage.doc)
} else {
check = true
}
}
}
if !check {
var supportedModulesString string
for _, supportedModule := range supportedModules() {
supportedModulesString += fmt.Sprintf("* %s\n", supportedModule)
}
return newConfigError(fmt.Sprintf("unsupported ansible task!\n\n%s\nSupported modules list:\n%s\n%s", dumpConfigSection(c), supportedModulesString, dumpConfigDoc(c.rawAnsible.rawImage.doc)))
}
}
return nil
}
func (c *rawAnsibleTask) blockDefined() bool {
return c.Block != nil || c.Rescue != nil || c.Always != nil
}
func supportedModules() []string {
var modules []string
// No Cloud modules
// No Clustering modules
// Commands Modules (no expect, psexec and telnet)
modules = append(modules, []string{"command", "shell", "raw", "script"}...)
// Crypto Modules
modules = append(modules, []string{"openssl_certificate", "openssl_csr", "openssl_privatekey", "openssl_publickey"}...)
// No Databases modules
// Files Modules (no fetch, patch, replace, synchronize, template, xml
modules = append(modules, []string{
"acl",
"archive",
"assemble",
"blockinfile",
"copy",
"file",
"replace",
"find",
"ini_file",
"iso_extract",
"lineinfile",
"stat",
"tempfile",
"unarchive",
"xattr",
}...)
// No Identity modules
// No Inventory modules
// No Messaging modules
// No Monitoring messages
// Net Tools Modules (only Basics)
modules = append(modules, []string{"get_url", "slurp", "uri"}...)
// No Network modules
// No Notification modules
// Packaging/Language Modules
modules = append(modules, []string{"bower", "bundler", "composer", "cpanm", "easy_install", "gem", "maven_artifact", "npm", "pear", "pip", "yarn"}...)
// Packaging/Os Modules
modules = append(modules, []string{
"apk",
"apt",
"apt_key",
"apt_repository",
"apt_rpm",
"dnf",
"dpkg_selections",
"debconf",
"homebrew",
"homebrew_cask",
"homebrew_tap",
"layman",
"macports",
"openbsd_pkg",
"opkg",
"package",
"pacman",
"pkg5",
"pkg5_publisher",
"pkgin",
"pkgng",
"pkgutil",
"portage",
"portinstall",
"pulp_repo",
"redhat_subscription",
"rhn_channel",
"rhn_register",
"rpm_key",
"slackpkg",
"sorcery",
"svr4pkg",
"swdepot",
"swupd",
"urpmi",
"xbps",
"yum",
"yum_repository",
"zypper",
"zypper_repository",
}...)
// No Remote Management modules
// No Source Control modules
// No Storage modules
// System Modules (only passwd management and locales)
modules = append(modules, []string{"cron", "user", "group", "getent", "locale_gen", "timezone"}...)
// Utilities Modules
modules = append(modules, []string{"meta", "assert", "debug", "fail", "set_fact", "wait_for"}...)
// No Web Infrastructure modules
// No Windows modules
return modules
}
func (c *rawAnsibleTask) toDirective() (*AnsibleTask, error) {
ansibleTask := &AnsibleTask{}
marshal, err := yaml.Marshal(c)
if err != nil {
return nil, err
}
var unmarshal map[string]interface{}
err = yaml.UnmarshalStrict(marshal, &unmarshal)
if err != nil {
return nil, err
}
ansibleTask.Config = unmarshal
ansibleTask.raw = c
return ansibleTask, nil
}