Skip to content

Commit

Permalink
Merge pull request #71 from yrobla/master
Browse files Browse the repository at this point in the history
Two fixes: update rhel mirror, isolate rhn subscription
  • Loading branch information
leifmadsen authored Feb 27, 2017
2 parents f0e5981 + 1d85b5a commit f57ced2
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 44 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ Jenkins slaves via the `[jenkins_slave]` and `[jenkins_slave:vars]` headers.
* slave_credentialsId
* slave_label

On a Red Hat system, subscription of slaves can be managed automatically
if you pass the right credentials:
* rhn_subscription_username
* rhn_subscription_password
* rhn_subscription_pool_id

## Example Override Variable File
Many of the values can be found in your OpenStack RC file, which can typically
be found in the _Access & Security_ section of the Horizon dashboard.
Expand Down Expand Up @@ -361,6 +355,19 @@ Each environment needs to have the following content:
- net_environment.yml: TripleO environment file that will be used. You can specify here all
the typical TripleO settings that need to be customized.

## RHN subscription

On a Red Hat system, subscription of slaves can be managed automatically
if you pass the right credentials:
* rhn_subscription_username
* rhn_subscription_password
* rhn_subscription_pool_id

Subscription can be managed automatically either on master or slaves, with the
flags:
* master_subscribe_rhn
* slave_subscribe_rhn

[toad_workflow]: https://raw.githubusercontent.com/redhat-nfvpe/toad/master/TOAD_Workflow.png

[//]: # (vim: set filetype=markdown:expandtab)
35 changes: 5 additions & 30 deletions jenkins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
group: jenkins
mode: "0755"

- include: rhel_register.yml
when: ansible_os_family == "RedHat" and master_subscribe_rhn|bool == True

- include: rhel_mirror_sync.yml
when: ansible_os_family == "RedHat" and master_mirror_sync|bool == true

Expand Down Expand Up @@ -200,36 +203,8 @@
mode: "0755"
become: true

- block:
- name: Unsubscribe previous system
redhat_subscription:
state: absent
ignore_errors: true

- name: Cleanup previous systems
command: "subscription-manager remove --all"

- name: Subscribe for RedHat systems
redhat_subscription:
state: present
username: "{{ rhn_subscription_username }}"
password: "{{ rhn_subscription_password }}"
pool: "{{ rhn_subscription_pool_id }}"

- name: Attach to the desired pool
command: "subscription-manager attach --pool={{ rhn_subscription_pool_id }}"
when: rhn_subscription_pool_id is defined

- name: Unsubscribe to previous repos
command: "subscription-manager repos --disable=*"
when: rhn_repos|length > 0

- name: Subscribe to the list of desired repos
command: "subscription-manager repos --enable {{ item }}"
with_items: "{{ rhn_repos }}"
when: rhn_repos|length > 0
become: true
when: ansible_os_family == "RedHat" and rhn_subscription_username is defined and rhn_subscription_password is defined
- include: rhel_register.yml
when: ansible_os_family == "RedHat" and slave_subscribe_rhn|bool == True

- include: rhel_mirror_sync.yml
when: ansible_os_family == "RedHat" and slave_mirror_sync|bool == true
Expand Down
10 changes: 5 additions & 5 deletions rhel_mirror_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@
when: iptables_service_status.stdout != 'active'

- name: Check if repo already exists
stat: path=/tmp/osp_repo
stat: path=/var/ftp/pub/osp_repo
register: repo_already_exists

- name: Create temporary directory for mirror
file:
path: /tmp/osp_repo
path: /var/ftp/pub/osp_repo
state: directory
mode: "0755"
when: repo_already_exists.stat.exists == False

- name: Mirror repository locally
shell: "reposync -l -n -p /tmp/osp_repo/ > /dev/null"
shell: "reposync -l -n -p /var/ftp/pub/osp_repo/ > /dev/null"
when: repo_already_exists.stat.exists == False

- name: Create repositories from local mirror
shell: "for DIR in `find /tmp/osp_repo -maxdepth 1 -mindepth 1 -type d`; do createrepo $DIR; done; > /dev/null"
shell: "for DIR in `find /var/ftp/pub/osp_repo -maxdepth 1 -mindepth 1 -type d`; do createrepo $DIR; done; > /dev/null"
when: repo_already_exists.stat.exists == False

- name: Execute repository creation script
script: "./scripts/create_repo.sh /tmp osp_repo"
script: "./scripts/create_repo.sh osp_repo"
become: true

42 changes: 42 additions & 0 deletions rhel_register.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
- name: fail if no credentials are provided
fail:
msg: "Please define rhn_subscription_username, rhn_subscription_password and rhn_subscription_pool_id to enroll your system"
when: rhn_subscription_username is undefined or rhn_subscription_username|bool == false or
rhn_subscription_password is undefined or rhn_subscription_password|bool == false or
rhn_subscription_pool_id is undefine or rhn_subscription_password|bool == false

- name: Unsubscribe previous system
redhat_subscription:
state: absent
ignore_errors: true
become: true

- name: Cleanup previous systems
command: "subscription-manager remove --all"
changed_when: false
become: true

- name: Subscribe for RedHat systems
redhat_subscription:
state: present
username: "{{ rhn_subscription_username }}"
password: "{{ rhn_subscription_password }}"
pool: "{{ rhn_subscription_pool_id }}"
become: true
changed_when: false

- name: Attach to the desired pool
command: "subscription-manager attach --pool={{ rhn_subscription_pool_id }}"
become: true
changed_when: false

- name: Unsubscribe to previous repos
command: "subscription-manager repos --disable=*"
when: rhn_repos|length > 0
become: true

- name: Subscribe to the list of desired repos
command: "subscription-manager repos --enable {{ item }}"
with_items: "{{ rhn_repos }}"
when: rhn_repos|length > 0
become: true
4 changes: 1 addition & 3 deletions scripts/create_repo.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
ADDRESS=$1
REPONAME=$2
REPONAME=$1
PUBLIC_ADDRESS=$(hostname --ip-address)
REPOPATH="/var/ftp/pub/"
REPOFILE="${REPOPATH}/${REPONAME}/osp.repo"

mkdir -p $REPOPATH
cp -R "${ADDRESS}/${REPONAME}/" ${REPOPATH}
rm $REPOFILE 2> /dev/null
touch $REPOFILE

Expand Down
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ filebeat_config_logging: |
name: mybeat.log
keepfiles: 7
# RHN subscription
master_subscribe_rhn: false
slave_subscribe_rhn: false
rhn_repos:
- rhel-7-server-rpms
- rhel-7-server-extras-rpms
Expand Down

0 comments on commit f57ced2

Please sign in to comment.