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 a Array[String] argument of repo IDs to be enabled #78

Merged
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rhsm

[![Build Status](https://travis-ci.org/voxpupuli/puppet-rhsm.png?branch=master)](https://travis-ci.org/voxpupuli/puppet-rhsm)[![Version](https://img.shields.io/puppetforge/v/puppet/rhsm.svg)](https://forge.puppet.com/puppet/rhsm)

## Overview

This module registers your systems with RedHat Subscription Management.
Expand Down Expand Up @@ -51,6 +53,33 @@ You shouldn't specify the protocol, subscription-manager will use HTTP. For prox

The proxy settings will be used to register the system and as connection option for all the YUM repositories generated in `/etc/yum.repos.d/redhat.repo`

### Enabled Repos

A string array of repo IDs can be provided as an argument to the class definition. This list will be used to enable the target repos if that has not already occurred.

The following example enables the server and optional RPMs:

```puppet
class { 'rhsm':
rh_user => 'myuser',
rh_password => 'mypassword',
enabled_repo_ids => [
Copy link
Contributor

Choose a reason for hiding this comment

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

I like it!

'rhel-7-server-rpms',
Copy link
Contributor

Choose a reason for hiding this comment

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

Has this been tested with non-RHEL repositories, e.g. custom repositories on Satellite 6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately no, I don't have Satellite in my environment so I haven't tested anything like that.

'rhel-7-server-optional-rpms'
]
}
```

Alternatively, hiera can be utilized to specify these arguments.

```yaml
rhsm::rh_user: myuser
rhsm::rh_password: mypassword
rhsm::enabled_repo_ids:
- 'rhel-7-server-rpms',
- 'rhel-7-server-optional-rpms'
```

### Satellite 6
Registering with Red Hat Satellite 6 needs some additional settings.

Expand Down
237 changes: 237 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
# Reference
<!-- DO NOT EDIT: This document was generated by Puppet Strings -->

## Table of Contents

**Classes**

* [`rhsm`](#rhsm): Subscribe the node to RHSM

**Defined types**

* [`rhsm::repo`](#rhsmrepo): Manage additional RedHat repositories

## Classes

### rhsm

rhsm

Subscribe the node to RHSM

Copyright 2014 Ger Apeldoorn, unless otherwise noted.

#### Examples

#####

```puppet
include rhsm
```

#####

```puppet
# Hierafile:
---
rhsm::rh_user: myuser
rhsm::rh_password: mypassword
```

#### Parameters

The following parameters are available in the `rhsm` class.

##### `rh_user`

Data type: `String`

User for the Customer Portal.
You need to specify either (rh_user and rh_password) or (org and activationkey)

Default value: `undef`

##### `rh_password`

Data type: `String`

Password for the rh_user account

Default value: `undef`

##### `org`

Data type: `String`

Organization to use

Default value: `undef`

##### `activationkey`

Data type: `String`

Activationkey to use

Default value: `undef`

##### `servername`

Data type: `String`

Servername, default provided
Used directly in rhsm.conf template

Default value: 'subscription.rhsm.redhat.com'

##### `serverprefix`

Data type: `String`

server.prefix to use
Used directly in rhsm.conf template
/rhsm for Satellite 6
/subscription for RHSM

Default value: '/subscription'

##### `serverport`

Data type: `Integer`

server.port to use
Used directly in rhsm.conf template

Default value: 443

##### `ca_cert_dir`

Data type: `String`

Server CA certificate location

Default value: '/etc/rhsm/ca/'

##### `repo_ca_cert_filename`

Data type: `String`

File containting the CA cert to use when generating yum repo configs
katello-server-ca.pem for Satellite 6
redhat-uep.pem for RHSM

Default value: 'redhat-uep.pem'

##### `repo_ca_cert_source`

Data type: `String`

URI, if set the content is used for CA file resource ${ca_cert_dir}/${repo_ca_cert_filename}
Possible values are puppet:, file: and http:

Default value: `undef`

##### `manage_repos`

Data type: `Integer`

1 if subscription manager should manage yum repos file or
0 if the subscription is only used for tracking purposes

Default value: 1

##### `full_refresh_on_yum`

Data type: `Integer`

rhsm.full_refresh_on_yum
Used directly in rhsm.conf template
1 for Satellite 6
0 for RHSM

Default value: 0

##### `pool`

Data type: `String`

Attach system to a specific pool instead of auto attach to compatible subscriptions

Default value: `undef`

##### `proxy_hostname`

Data type: `String`

Proxy hostname

Default value: `undef`

##### `proxy_port`

Data type: `Integer`

Proxy port

Default value: `undef`

##### `proxy_user`

Data type: `String`

Proxy user

Default value: `undef`

##### `proxy_password`

Data type: `String`

Proxy password

Default value: `undef`

##### `baseurl`

Data type: `String`

Base URL for rhsm, default provided

Default value: 'https://cdn.redhat.com'

##### `package_ensure`

Data type: `String`

Whether to install subscription-manager

Default value: 'latest'

##### `enabled_repo_ids`

Data type: `Optional[Array[String]]`

nabled_repo_ids [Array[String]
A listing of the Repo IDs to provide to the subscription-manager repo
--enable command.

Default value: []

## Defined types

### rhsm::repo

rhsm::repo

Target file is /etc/yum.repos.d/redhat.repo

Copyright 2014 Ger Apeldoorn, unless otherwise noted.

#### Examples

#####

```puppet
::rhsm::repo { "rhel-${::operatingsystemmajrelease}-server-extras-rpms": }
```

4 changes: 4 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
lookup_options:
rhsm::enabled_repo_ids:
merge: 'unique'
12 changes: 12 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
version: 5
defaults:
# The default value for "datadir" is "data" under the same directory as the hiera.yaml
# file (this file)
# When specifying a datadir, make sure the directory exists.
# See https://docs.puppet.com/puppet/latest/environments.html for further details on environments.
datadir: data
data_hash: yaml_data
hierarchy:
- name: "Common Data"
path: 'common.yaml'
49 changes: 49 additions & 0 deletions lib/facter/rhsm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Facter.add(:rhsm, type: :aggregate) do
Copy link
Contributor

Choose a reason for hiding this comment

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

This fact is a major change. For example, we rely on rhsm_subscription_type for a Satellite 5 to 6 migration.

confine :os do |os|
os['family'] == 'RedHat'
end

# List the currently enabled repositories
if File.exist? '/usr/bin/subscription-manager'
chunk(:enabled_repo_ids) do
repos = Array.[]
repo_list = Facter::Core::Execution.exec("subscription-manager repos --list-enabled | awk '/Repo ID:/ {print $3}'")
repo_list.each_line do |line|
repos.push(line.strip)
end
{ enabled_repo_ids: repos }
end
end

# Determine the subscription type
chunk(:subscription_type) do
if File.exist? '/etc/sysconfig/rhn/systemid'
{ subscription_type: 'rhn_classic' }
elsif File.exist? '/etc/pki/consumer/cert.pem'
{ subscription_type: 'rhsm' }
else
{ subscription_type: 'unknown' }
end
end
end

# Backward compatibility
Facter.add('rhsm_repos') do
confine :os do |os|
os['family'] == 'RedHat'
end

setcode do
Facter.value(:rhsm)[:enabled_repo_ids]
end
end

Facter.add('rhsm_subscription_type') do
confine :os do |os|
os['family'] == 'RedHat'
end

setcode do
Facter.value(:rhsm)[:subscription_type]
end
end
11 changes: 0 additions & 11 deletions lib/facter/rhsm_repos.rb

This file was deleted.

12 changes: 0 additions & 12 deletions lib/facter/rhsm_subscription_type.rb

This file was deleted.

Loading