Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for managing tags #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixtures:
forge_modules:
stdlib: "puppetlabs/stdlib"
9 changes: 9 additions & 0 deletions manifests/current.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# Whether to obfuscate IP addresses.
# @param obfuscate_hostname
# Whether to obfuscate hostname.
# @param tags
# Data Hash to populate tags.yaml file
#
#
# @author Lindani Phiri <[email protected]>
# @author Dan Varga <[email protected]>
Expand All @@ -48,6 +51,7 @@
$auto_update = undef,
$obfuscate = undef,
$obfuscate_hostname = undef,
Hash $tags = {},
) {
package { $package_name:
ensure => installed,
Expand Down Expand Up @@ -93,6 +97,11 @@
}
}

file { "/etc/${package_name}/tags.yaml":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll admit I don't know too much about the insights client (my knowledge is mainly on the Puppet side). Is this something that should be there before it's registered?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I've heard it will be picked up by the agent, but not directly. If you want it directly you have to unregister/register the client again. That is for the file-redaction.yaml file.

content => to_yaml($tags),
require => Package[$package_name],
}

exec { "/usr/bin/${package_name} --register":
creates => "/etc/${package_name}/.registered",
unless => "/usr/bin/test -f /etc/${package_name}/.unregistered",
Expand Down
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
# @param deployment_style
# How the module should be deploy. Can be undef (auto),
# current (6.10+ or 7.5+) or old.
# @param tags
# Data Hash to populate tags.yaml file
#
# @author Lindani Phiri <[email protected]>
# @author Dan Varga <[email protected]>
Expand All @@ -49,6 +51,7 @@
$auto_update = undef,
$obfuscate = undef,
$obfuscate_hostname = undef,
Hash $tags = {},
Optional[Enum['current', 'old']] $deployment_style = undef,
) {
if $deployment_style {
Expand All @@ -75,6 +78,7 @@
auto_update => $auto_update,
obfuscate => $obfuscate,
obfuscate_hostname => $obfuscate_hostname,
tags => $tags,
}
contain "access_insights_client::${class_name}"
}
7 changes: 7 additions & 0 deletions manifests/old.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
# Whether to obfuscate IP addresses.
# @param obfuscate_hostname
# Whether to obfuscate hostname.
# @param tags
# Data Hash to populate tags.yaml file ---> This will not work for the old style of deployment.
#
# @author Lindani Phiri <[email protected]>
# @author Dan Varga <[email protected]>
Expand All @@ -49,7 +51,12 @@
$auto_update = undef,
$obfuscate = undef,
$obfuscate_hostname = undef,
Hash $tags = {},
) {
if !$tags.empty {
fail('You cant use tags with this implementation')
}

package { $package_name:
ensure => installed,
}
Expand Down
4 changes: 4 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
{
"name": "puppet",
"version_requirement": ">= 6.1.0 < 8.0.0"
},
{
"name": "puppetlabs-stdlib",
"version_requirement": ">= 4.20.0"
}
]
}
9 changes: 9 additions & 0 deletions spec/classes/current_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,14 @@
it { is_expected.to contain_file('/etc/cron.weekly/insights-client').with_ensure('absent') }
it { is_expected.to contain_exec('/usr/bin/insights-client --register') }
it { is_expected.to contain_service('insights-client.timer') }
it { is_expected.to contain_file('/etc/insights-client/tags.yaml').with_content(%r{^--- \{\}$}) }

context 'with tags' do
let :params do
{tags: {'foo': 'bar'}}
end

it { is_expected.to contain_file('/etc/insights-client/tags.yaml').with_content(%r{^---\nfoo: bar$}) }
end
end
end