Skip to content

Commit 6ed241d

Browse files
authored
Add --skip-tags support to provision (#616)
Works the same as `tags` but for skipping tags.
1 parent a5cb2a0 commit 6ed241d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cmd/provision.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ProvisionCommand struct {
2323
flags *flag.FlagSet
2424
extraVars string
2525
tags string
26+
skipTags string
2627
Trellis *trellis.Trellis
2728
verbose bool
2829
}
@@ -32,6 +33,7 @@ func (c *ProvisionCommand) init() {
3233
c.flags.Usage = func() { c.UI.Info(c.Help()) }
3334
c.flags.StringVar(&c.extraVars, "extra-vars", "", "Additional variables which are passed through to Ansible as 'extra-vars'")
3435
c.flags.StringVar(&c.tags, "tags", "", "only run roles and tasks tagged with these values")
36+
c.flags.StringVar(&c.skipTags, "skip-tags", "", "skip roles and tasks tagged with these values")
3537
c.flags.BoolVar(&c.verbose, "verbose", false, "Enable Ansible's verbose mode")
3638
}
3739

@@ -82,6 +84,10 @@ func (c *ProvisionCommand) Run(args []string) int {
8284
playbook.AddArg("--tags", c.tags)
8385
}
8486

87+
if c.skipTags != "" {
88+
playbook.AddArg("--skip-tags", c.skipTags)
89+
}
90+
8591
if environment == "development" {
8692
os.Setenv("ANSIBLE_HOST_KEY_CHECKING", "false")
8793
playbook.SetName("dev.yml")
@@ -135,6 +141,7 @@ Arguments:
135141
136142
Options:
137143
--extra-vars (multiple) Set additional variables as key=value or YAML/JSON, if filename prepend with @
144+
--skip-tags (multiple) Skip roles and tasks tagged with these values
138145
--tags (multiple) Only run roles and tasks tagged with these values
139146
--verbose Enable Ansible's verbose mode
140147
-h, --help Show this help
@@ -150,6 +157,7 @@ func (c *ProvisionCommand) AutocompleteArgs() complete.Predictor {
150157
func (c *ProvisionCommand) AutocompleteFlags() complete.Flags {
151158
return complete.Flags{
152159
"--extra-vars": complete.PredictNothing,
160+
"--skip-tags": complete.PredictNothing,
153161
"--tags": complete.PredictNothing,
154162
"--verbose": complete.PredictNothing,
155163
}

cmd/provision_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ func TestProvisionRun(t *testing.T) {
9898
"ansible-playbook dev.yml --tags=users -e env=development",
9999
0,
100100
},
101+
{
102+
"with_skip_tags",
103+
[]string{"-skip-tags", "users", "development"},
104+
"ansible-playbook dev.yml --skip-tags=users -e env=development",
105+
0,
106+
},
107+
{
108+
"with_tags_and_skip_tags",
109+
[]string{"-tags", "deploy", "-skip-tags", "users", "development"},
110+
"ansible-playbook dev.yml --tags=deploy --skip-tags=users -e env=development",
111+
0,
112+
},
101113
{
102114
"with_extra_vars",
103115
[]string{"-extra-vars", "k=v foo=bar", "development"},

0 commit comments

Comments
 (0)