Ondřej Ezr
2020-03-13 25be12cc5df93cf80acbd2908723c93d40057f1f
Satellite content-view role use foreman-ansible-modules (#1304)

Thanks for the enhancements.
1 files deleted
2 files added
2 files modified
213 ■■■■■ changed files
ansible/roles/satellite-manage-content-view/README.adoc 69 ●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-content-view/tasks/_create_content_view.yml 23 ●●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-content-view/tasks/main.yml 4 ●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-content-view/tasks/version_6.4.yml 93 ●●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-content-view/tasks/version_6.x.yml 24 ●●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-content-view/README.adoc
@@ -3,7 +3,7 @@
:tag1: configure_satellite
:tag2: configure_satellite_content_view
:main_file: tasks/main.yml
:version_file: tasks/version_6.4.yml
:version_file: tasks/version_6.7.yml
Role: {role}
============
@@ -16,14 +16,13 @@
Following are the requirements:
. Satellite must be install and setup.
. Hammer cli config must be configured/updated with privileged user and password to run the satellite cli.
. Repository should be enabled and syncronized in the organization to add in content-view.
. Repository should be enabled and syncronized in the organization to add in content-view.
Role Variables
--------------
* Following are the variable which needs to be defined
* Following are the variable which needs to be defined
|===
|satellite_version: "Digit" |Required |satellite version
@@ -32,39 +31,38 @@
|org_description: "String" |Required | Organization description
| satellite_content: {Dictionary} |Required | Main dictionary variable
| content_view: "String" | Requird | Name of content-view
| content_view_update: bool | Not-required, Default(false) |True/false
| repos: [list] | Required | List of repository name
| content_view_update: bool | Optional(*no*) | Wheter to publish new version
| repos: [list] | Required | List of repository name
|===
* Exammple variables
[source=text]
----
satellite_version: 6.4
satellite_version: 6.7
org: "gpte"
org_label: "gpte"
org_description: "Global Partner Training and Enablement"
satellite_content:
  - name:             "Ansible server"
    content_view:     "Ansible servers content"
    content_view_update: False
    repos:
      - name: 'Red Hat Enterprise Linux 7 Server (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
    content_view_update: yes
    repos:
      - name: 'Red Hat Enterprise Linux 7 Server (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
        basearch: 'x86_64'
        releasever:  '7Server'
      - name: 'Red Hat Satellite Maintenance 6 (for RHEL 7 Server) (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
        product: 'Red Hat Enterprise Linux Server'
        basearch: 'x86_64'
  - name:             "Three Tier App"
    content_view:     "Three Tier App"
    repos:
      - name: 'Red Hat Enterprise Linux 7 Server (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
        basearch: 'x86_64'
        releasever:  '7Server'
    repos:
      - name: 'Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)'
        product: 'Red Hat Enterprise Linux for x86_64'
        releasever:  '8'
----
Tags
@@ -93,31 +91,30 @@
[source=text]
----
[user@desktop ~]$ cat sample_vars.yml
satellite_version: 6.4
satellite_version: 6.7
org: "gpte"
org_label: "gpte"
org_description: "Global Partner Training and Enablement"
satellite_content:
  - name:             "Ansible server"
    content_view:     "Ansible servers content"
    content_view_update: False
    repos:
      - name: 'Red Hat Enterprise Linux 7 Server (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
    content_view_update: yes
    repos:
      - name: 'Red Hat Enterprise Linux 7 Server (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
        basearch: 'x86_64'
        releasever:  '7Server'
      - name: 'Red Hat Satellite Maintenance 6 (for RHEL 7 Server) (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
        product: 'Red Hat Enterprise Linux Server'
        basearch: 'x86_64'
  - name:             "Three Tier App"
    content_view:     "Three Tier App"
    repos:
      - name: 'Red Hat Enterprise Linux 7 Server (RPMs)'
        product: 'Red Hat Enterprise Linux Server'
        basearch: 'x86_64'
        releasever:  '7Server'
    repos:
      - name: 'Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)'
        product: 'Red Hat Enterprise Linux for x86_64'
        releasever:  '8'
[user@desktop ~]$ cat playbook.yml
- hosts: satellite.example.com
@@ -132,9 +129,9 @@
Tips to update Role
------------------
To extend role works for other version, create new file named  version_{{satellite_version}}.yml and import newly created file in main.yml
To extend role works for other version, if needed create new file named  version_{{satellite_version}}.yml and import newly created file in main.yml
for reference look at link:{main_file}[main.yml] and link:{version_file}[version_6.4.yml]
for reference look at link:{main_file}[main.yml] and link:{version_file}[version_6.x.yml]
Author Information
ansible/roles/satellite-manage-content-view/tasks/_create_content_view.yml
New file
@@ -0,0 +1,23 @@
- name: Parse names to proper repo names
  set_fact:
    content_temp_names: "{{
        (content.repos | map(attribute='name') | map('regex_replace', '[()]')) |
          zip(
            (content.repos | map(attribute='basearch', default='MISSING')),
            (content.repos | map(attribute='releasever', default='MISSING'))
          ) |
          map('join', ' ') | map('regex_replace', ' MISSING') | list
      }}"
    content_temp_repositories: []
- set_fact:
    content_temp_repositories: "{{ content_temp_repositories + [{ 'name': content_temp_names[item.0], 'product': item.1.product}] }}"
  with_indexed_items: "{{ content.repos }}"
- theforeman.foreman.katello_content_view:
    username: "{{ satellite_admin }}"
    password: "{{ satellite_admin_password }}"
    server_url: "https://{{ publicname }}"
    validate_certs: no
    name: "{{ content.content_view }}"
    organization: "{{ org }}"
    repositories: "{{ content_temp_repositories }}"
ansible/roles/satellite-manage-content-view/tasks/main.yml
@@ -1,8 +1,8 @@
---
## Import for version satellite 6.4 ##
- import_tasks: version_6.4.yml
  when: satellite_version == 6.4
- import_tasks: version_6.x.yml
  when: satellite_version >= 6.4
  tags:
    - configure_satellite
    - configure_satellite_content_view
ansible/roles/satellite-manage-content-view/tasks/version_6.4.yml
File was deleted
ansible/roles/satellite-manage-content-view/tasks/version_6.x.yml
New file
@@ -0,0 +1,24 @@
---
- name: "Create content views"
  include_tasks: '_create_content_view.yml'
  with_items: "{{ satellite_content }}"
  loop_control:
    loop_var: content
  tags:
    - configure_satellite
    - configure_satellite_content_view
- name: "Ensure content view version is in all environments"
  theforeman.foreman.katello_content_view_version:
    username: "{{ satellite_admin }}"
    password: "{{ satellite_admin_password }}"
    server_url: "https://{{ publicname }}"
    validate_certs: no
    content_view: "{{ item.content_view }}"
    organization: "{{ org }}"
    version: "{{ item.content_view_update | d(false) | ternary(omit, 1.0) }}"
    lifecycle_environments: "{{ lifecycle_environment_path | map(attribute='name') | list }}"
  with_items: "{{ satellite_content }}"
  tags:
    - configure_satellite
    - configure_satellite_content_view