From 5fbd67697473c03390c3cc33cb0a46561699a0c9 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Thu, 9 Jun 2016 17:31:41 -0400 Subject: [PATCH] Initial commit --- .travis.yml | 29 +++++++++++++++++++++++++++++ README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ defaults/main.yml | 9 +++++++++ meta/main.yml | 19 +++++++++++++++++++ tasks/main.yml | 23 +++++++++++++++++++++++ tests/Vagrantfile | 19 +++++++++++++++++++ tests/inventory | 1 + tests/test.yml | 5 +++++ tests/vagrant.yml | 6 ++++++ vars/main.yml | 2 ++ 10 files changed, 159 insertions(+) create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 defaults/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 tests/Vagrantfile create mode 100644 tests/inventory create mode 100644 tests/test.yml create mode 100644 tests/vagrant.yml create mode 100644 vars/main.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..33e4d52 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +sudo: required +dist: trusty + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..d860e2e --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +Red Hat Subscription +========= + +Manage Red Hat subscritions and repositories. + +Requirements +------------ + +Current Red Hat subscription. + +Role Variables +-------------- + +| Name | Default Value | Description | +|-------------------|---------------------|----------------------| +| `rhn_username` | `{{ lookup('env', 'RHN_USERNAME') }}` | Red Hat Port username. | +| `rhn_password` | `{{ lookup('env', 'RHN_PASSWORD') }}` | Red Hat Portal password. | +| `rhsub_state` | `enable` | Whether to enable or disable a Red Hat subscription. | +| `rhsub_autosubscribe` | `True` | Whether or not to autosubscibe to available repositories. If set, will skip the task that manages individual repositories. | +| `rhsub_repos` | `{}` | List of repositories to enable or disable. See `defaults/main.yml` for examples. | + +Dependencies +------------ + +None. + +Example Playbook +---------------- + + - hosts: all + + vars: + rhn_username: bob.smith@acme.com + rhn_password: "{{ vault_rhn_password }}" + rhsub_repos: + - name: rhel-7-server-extras-rpms + state: enable + + roles: + - samdoran.redhat-subscription + +License +------- + +MIT + diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..0420270 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +rhn_username: "{{ lookup('env', 'RHN_USERNAME') }}" +rhn_password: "{{ lookup('env', 'RHN_PASSWORD') }}" + +rhsub_state: enable +rhsub_autosubscribe: True + +rhsub_repos: {} + # - name: rhel-7-server-extras-rpms # wildcard or repo name + # state: enable # enable or disable diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..32838ee --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,19 @@ +galaxy_info: + author: Sam Doran + description: "Manage Red Hat subscription and repositories." + company: + license: MIT + min_ansible_version: 1.9 + + platforms: + - name: EL + versions: + - 6 + - 7 + + galaxy_tags: + - system + - redhat + - subscription + +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..295db70 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,23 @@ +- name: Check that this is Red Hat + assert: + that: "{{ ansible_distribution }} == 'RedHat'" + tags: + - rhsub + +- name: Register Red Hat subscription + redhat_subscription: + username: "{{ rhn_username }}" + password: "{{ rhn_password }}" + state: "{{ rhsub_state }}" + autosubscribe: "{{ rhsub_autosubscribe }}" + tags: + - rhsub + - rhsub_register + +- name: Configure repository subscriptions + command: subscription-manage repos --{{ item.state }} --{{ item.name }} + with_items: "{{ rhsub_repos }}" + when: not rhsub_autosubscribe + tags: + - rhsub + - rhsub_repos diff --git a/tests/Vagrantfile b/tests/Vagrantfile new file mode 100644 index 0000000..4761c77 --- /dev/null +++ b/tests/Vagrantfile @@ -0,0 +1,19 @@ +Vagrant.configure(2) do |config| + + # RHEL 6 + config.vm.define "rhel6" do |rhel6| + rhel6.vm.box = "samdoran/rhel6" + rhel6.vm.hostname = "java-rhel6" + end + + # RHEL 7 + config.vm.define "rhel7" do |rhel7| + rhel7.vm.box = "samdoran/rhel7" + rhel7.vm.hostname = "java-rhel7" + end + + config.vm.provision "ansible" do |ansible| + ansible.playbook = "vagrant.yml" + end + +end diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..d18580b --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost \ No newline at end of file diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..0586deb --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - redhat-subscription \ No newline at end of file diff --git a/tests/vagrant.yml b/tests/vagrant.yml new file mode 100644 index 0000000..97a3892 --- /dev/null +++ b/tests/vagrant.yml @@ -0,0 +1,6 @@ +--- +- hosts: all + remote_user: vagrant + become: True + roles: + - redhat-subscription diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..c752351 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for redhat-subscription