-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from gavin-romig-koch/redhatinsights/add-insigh…
…ts-client add insights-client RPM
- Loading branch information
Showing
14 changed files
with
337 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.