Skip to content

Commit

Permalink
Merge pull request #2 from gavin-romig-koch/redhatinsights/add-insigh…
Browse files Browse the repository at this point in the history
…ts-client

add insights-client RPM
  • Loading branch information
gavin-romig-koch authored Sep 14, 2018
2 parents 29ff3c0 + 9650fb8 commit d4c2449
Show file tree
Hide file tree
Showing 14 changed files with 337 additions and 46 deletions.
13 changes: 13 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
line-length: disable
# NOTE(retr0h): Templates no longer fail this lint rule.
# Uncomment if running old Molecule templates.
# truthy: disable
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
insights-client
========

Installs, configures, and registers a system to the [Red Hat Insights service](http://access.redhat.com/insights). This role is intended to work on Red Hat Enterprise Linux, though it will generally work on any yum based system that has access to the redhat-access-insights RPM.
Installs, configures, and registers a system to the [Red Hat Insights service](http://access.redhat.com/insights). This role is intended to work on Red Hat Enterprise Linux, though it will generally work on any yum based system that has access to the insights-client RPM or the redhat-access-insights RPM.

Requirements
------------
Expand Down
3 changes: 2 additions & 1 deletion examples/example-insights-client-playbook.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- hosts: all
roles:
- { role: RedHatInsights.insights-client }
- { role: RedHatInsights.insights-client }
4 changes: 3 additions & 1 deletion files/insights.fact
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
if [ -e /etc/redhat-access-insights/machine-id ]; then
if [ -e /etc/insights-client/machine-id ]; then
SYSTEM_ID=$(cat /etc/insights-client/machine-id)
elif [ -e /etc/redhat-access-insights/machine-id ]; then
SYSTEM_ID=$(cat /etc/redhat-access-insights/machine-id)
fi
if [ -n "${SYSTEM_ID}" ]; then
Expand Down
20 changes: 10 additions & 10 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
galaxy_info:
author: Red Hat, Inc
description: Install and configure Red Hat Insights Client
company: Red Hat, Inc.
license: Apache License 2.0
min_ansible_version: 1.2
platforms:
author: Red Hat, Inc
description: Install and configure Red Hat Insights Client
company: Red Hat, Inc.
license: Apache License 2.0
min_ansible_version: 1.2
platforms:
- name: EL
versions:
- 6
- 7
categories:
- 6
- 7
categories:
- packaging
- system
dependencies: []
dependencies: []
65 changes: 65 additions & 0 deletions molecule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Testing insights-client role with Molecule
==========================================

The role uses [Molecule](https://github.com/metacloud/molecule) for testing. See below
for installing and running Molecule.

Because of what this role is intended to do, in order to test this role, you need a copy
of Red Hat Enterprise Linux and a subscription to the
[Red Hat Insights service](http://access.redhat.com/insights) service.

Here Molecule is configured to test this role on three libvirt Vagrant boxes named
'rhel68-base', 'rhel72-base', and 'rhel74-base'. The number or names of the boxes tested
by the default scenario can be changed by editing the 'platforms' section
of the 'molecule/default/molecule.yml' file. The names can be arbitrary as long as they refer
to Vagrant boxes available on the test machine. The command 'vagrant box list' will tell you
which boxes are available on the test machine. The tests should work for any currently supported
version of RHEL.

Vagrant boxes for RHEL are not generally available, though both Red Hat Developer Support and
Red Hat Support sites have instructions for creating Vagrant boxes from RHEL images.

Since this role actually registers with the Insights service, the test boxes must register
with the Red Hat Portal. Portal credentials must be supplied in the file
'~/redhat-portal-creds.yml', in the format described below.


Installing Molecule
-------------------

The easiest way to install Molecule at the point of writing this, is to use a Python virtual environment and pip.

```bash
$ virtualenv --no-site-packages .venv
$ source .venv/bin/activate
$ pip install molecule ansible python-vagrant
```

Review or Edit the file 'molecule/default/molecule.yml'
-------------------------------------------------------

Make sure the boxes specified in the 'platforms' section are boxes that are actually available
on the test machine.

Review or Edit the portal creds file: ~/redhat-portal-creds.yml
-------------------------------------------------------

Create a YAML file, ~/redhat-portal-creds.yml, on the test machine containing the following,
with XXXXXX/YYYYYY replaced with our Insights/Portal/RHSM username/password:

redhat_portal_username: XXXXXX
redhat_portal_password: YYYYYY

Run the molecule test
---------------------

```bash
$ molecule test
```

or if you need more details from the error messages:

```bash
$ molecule test --debug
```

17 changes: 17 additions & 0 deletions molecule/default/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*******
Install
*******

Requirements
============

* Vagrant
* Virtualbox, Parallels, VMware Fusion, VMware Workstation or VMware Desktop
* python-vagrant

Install
=======

.. code-block:: bash
$ sudo pip install python-vagrant
60 changes: 60 additions & 0 deletions molecule/default/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
- name: Create
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
tasks:
- name: Create molecule instance(s)
molecule_vagrant:
instance_name: "{{ item.name }}"
instance_interfaces: "{{ item.interfaces | default(omit) }}"
instance_raw_config_args: "{{ item.instance_raw_config_args | default(omit) }}"

config_options: "{{ item.config_options | default(omit) }}"

platform_box: "{{ item.box }}"
platform_box_version: "{{ item.box_version | default(omit) }}"
platform_box_url: "{{ item.box_url | default(omit) }}"

provider_name: "{{ molecule_yml.driver.provider.name }}"
provider_memory: "{{ item.memory | default(omit) }}"
provider_cpus: "{{ item.cpus | default(omit) }}"
provider_options: "{{ item.provider_options | default(omit) }}"
provider_raw_config_args: "{{ item.provider_raw_config_args | default(omit) }}"

provision: "{{ item.provision | default(omit) }}"

state: up
register: server
with_items: "{{ molecule_yml.platforms }}"

# NOTE(retr0h): Vagrant/VBox sucks and parallelizing instance creation
# causes issues.

# Mandatory configuration for Molecule to function.

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.Host }}",
'address': "{{ item.HostName }}",
'user': "{{ item.User }}",
'port': "{{ item.Port }}",
'identity_file': "{{ item.IdentityFile }}", }
with_items: "{{ server.results }}"
register: instance_config_dict
when: server.changed | bool

- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server.changed | bool

- name: Dump instance config
copy:
# NOTE(retr0h): Workaround for Ansible 2.2.
# https://github.com/ansible/ansible/issues/20885
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
35 changes: 35 additions & 0 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---

- name: Destroy
hosts: localhost
connection: local
gather_facts: false
no_log: "{{ not lookup('env', 'MOLECULE_DEBUG') | bool }}"
tasks:
- name: Destroy molecule instance(s)
molecule_vagrant:
instance_name: "{{ item.name }}"
platform_box: "{{ item.box }}"
provider_name: "{{ molecule_yml.driver.provider.name }}"
force_stop: "{{ item.force_stop | default(true) }}"

state: destroy
register: server
with_items: "{{ molecule_yml.platforms }}"

# NOTE(retr0h): Vagrant/VBox sucks and parallelizing instance deletion
# causes issues.

# Mandatory configuration for Molecule to function.

- name: Populate instance config
set_fact:
instance_conf: {}

- name: Dump instance config
copy:
# NOTE(retr0h): Workaround for Ansible 2.2.
# https://github.com/ansible/ansible/issues/20885
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
26 changes: 26 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
dependency:
name: galaxy
driver:
name: vagrant
provider:
name: libvirt
lint:
name: yamllint
platforms:
- name: instance-rhel72
box: rhel72-base
- name: instance-rhel74
box: rhel74-base
- name: instance-rhel68
box: rhel68-base
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
14 changes: 14 additions & 0 deletions molecule/default/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Converge
hosts: all
become: true
tasks:

- name: Invoke role insights-client-role
import_role:
name: insights-client-role

- name: Un-register from RHSM
redhat_subscription:
state: absent
when: ansible_distribution == "RedHat"
22 changes: 22 additions & 0 deletions molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Prepare
hosts: all
become: true
tasks:

- name: Install libselinux-python, Ansible clients need this on RHEL
package:
name: libselinux-python
when: ansible_distribution == "RedHat"

- name: Pull in the Red Hat Portal credentials from home directory
include_vars:
file: "~/redhat-portal-creds.yml"

- name: Register with and autosubscribe to RHSM
redhat_subscription:
username: "{{ redhat_portal_username }}"
password: "{{ redhat_portal_password }}"
autosubscribe: true
state: present
when: ansible_distribution == "RedHat"
17 changes: 17 additions & 0 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

import testinfra.utils.ansible_runner

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')


def test_hosts_file(host):
if host.package('insights-client').is_installed:
insights_name = 'insights-client'
else:
insights_name = 'redhat-access-insights'

insights_conf_file = '/etc/'+insights_name+'/'+insights_name+'.conf'
assert host.package(insights_name).is_installed
assert host.file(insights_conf_file).exists
Loading

0 comments on commit d4c2449

Please sign in to comment.