Skip to content

Commit

Permalink
Tag editing (#4180)
Browse files Browse the repository at this point in the history
* Tag editing

Signed-off-by: Ian Maddaus <[email protected]>

* Additional revisions

Signed-off-by: Ian Maddaus <[email protected]>

---------

Signed-off-by: Ian Maddaus <[email protected]>
  • Loading branch information
IanMadd authored Sep 12, 2023
1 parent 8fb91e5 commit 060ec7f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
6 changes: 2 additions & 4 deletions content/reusable/md/chef_tags.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
A tag is a custom description that is applied to a node. A tag, once
applied, can be helpful when managing nodes using knife or when building
recipes by providing alternate methods of grouping similar types of
information.
A tag is a custom description that's applied to a node.
A tag, once applied, can be helpful when managing nodes using knife or when building recipes by providing alternate methods of grouping similar types of information.
33 changes: 17 additions & 16 deletions content/reusable/md/cookbooks_recipe_tags.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
Tags can be added and removed. Machines can be checked to see if they
already have a specific tag. To use tags in your recipe simply add the
following:
You can add tags, remove tags, and check if nodes have a specific tag.

To add a tag in your recipe, use `tag` with the tag name you want to apply to a node.

```ruby
tag('mytag')
tag('tag-name')
```

To test if a machine is tagged, add the following:
To test if a machine is tagged with a specific tag, use `tagged?` with the tag name.

```ruby
tagged?('mytag')
tagged?('tag-name')
```

to return `true` or `false`. `tagged?` can also use an array as an
argument.
This will return `true` or `false`.

`tagged?` also accepts an array as an argument.

To remove a tag:
Remove a tag using `untag`.

```ruby
untag('mytag')
untag('tag-name')
```

For example:

```ruby
tag('machine')
tag('test_node')

if tagged?('machine')
if tagged?('test_node')
Chef::Log.info("Hey I'm #{node['tags']}")
end

untag('machine')
untag('test_node')

unless tagged?('machine')
unless tagged?('test_node')
Chef::Log.info('I am not tagged')
end
```

Will return something like this:

```none
[Thu, 22 Jul 2010 18:01:45 +0000] INFO: Hey I'm machine
[Thu, 22 Jul 2010 18:01:45 +0000] INFO: I has no tagz
[Thu, 22 Jul 2010 18:01:45 +0000] INFO: Hey I'm test_node
[Thu, 22 Jul 2010 18:01:45 +0000] INFO: I am not tagged
```

0 comments on commit 060ec7f

Please sign in to comment.