Ondřej Ezr
2020-03-11 0dfc026596fbc7cb5d0c73a884b424b523dca7e4
Satellite role - create organization through foreman-ansible-modules (#1289)

* Satellite role - create organization through foreman-ansible-modules

* Install dependencies for test

* Add collection requirements to satellite configs

* in satellite roles, include_role instead of import_role

If a role needs something from galaxy, it must be included dynamically, not imported,
otherwise it's a syntax error.

Indeed, the galaxy roles and collections are imported at runtime.

* Test galaxy roles and collection in syntax-checks.sh

* Support galaxy collections

closes #1282

* Add apipy to test requirements

Co-authored-by: Guillaume Coré <gucore@redhat.com>
3 files added
7 files modified
159 ■■■■ changed files
ansible/configs/satellite-multi-region/requirements.yml 4 ●●●● patch | view | raw | blame | history
ansible/configs/satellite-multi-region/software.yml 52 ●●●●● patch | view | raw | blame | history
ansible/configs/satellite-vm/requirements.yml 4 ●●●● patch | view | raw | blame | history
ansible/configs/satellite-vm/software.yml 42 ●●●●● patch | view | raw | blame | history
ansible/install_galaxy_roles.yml 20 ●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-organization/README.adoc 14 ●●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-organization/tasks/main.yml 4 ●●●● patch | view | raw | blame | history
ansible/roles/satellite-manage-organization/tasks/version_6.x.yml 10 ●●●●● patch | view | raw | blame | history
tests/static/requirements.txt 1 ●●●● patch | view | raw | blame | history
tests/static/syntax-check.sh 8 ●●●● patch | view | raw | blame | history
ansible/configs/satellite-multi-region/requirements.yml
New file
@@ -0,0 +1,4 @@
---
collections:
- name: theforeman.foreman
  version: '0.6.0'
ansible/configs/satellite-multi-region/software.yml
@@ -6,35 +6,51 @@
  tasks:
    - debug:
        msg: "Software tasks Started"
- name: Configuring satellite Hosts
  hosts: satellites
  become: True
  gather_facts: True
  roles:
    - { role: "satellite-public-hostname" }
    - { role: "satellite-installation",                 when: install_satellite   }
    # # - { role: "satellite-hammer-cli",                 when: install_satellite   }
    - { role: "satellite-manage-organization",          when: configure_satellite }
    - { role: "satellite-manage-manifest",              when: configure_satellite }
    - { role: "satellite-manage-subscription",          when: configure_satellite }
    - { role: "satellite-manage-sync",                  when: configure_satellite }
    # - { role: "satellite-manage-lifecycle",             when: configure_satellite }
    # - { role: "satellite-manage-content-view",          when: configure_satellite }
    # - { role: "satellite-manage-activationkey",         when: configure_satellite }
    # - { role: "satellite-manage-capsule-certificate",   when: configure_satellite }
  tasks:
    - import_role:
        name: satellite-public-hostname
    - when: install_satellite
      include_role:
        name: "{{ _role }}"
      loop_control:
        loop_var: _role
      loop:
        - satellite-installation
        # - satellite-hammer-cli
    - when: configure_satellite
      include_role:
        name: "{{ _role }}"
      loop_control:
        loop_var: _role
      loop:
        - satellite-manage-organization
        - satellite-manage-manifest
        - satellite-manage-subscription
        - satellite-manage-sync
        # - satellite-manage-lifecycle
        # - satellite-manage-content-view
        # - satellite-manage-activationkey
        # - satellite-manage-capsule-certificate
- name: Configuring capsule Hosts
  hosts: capsules
  become: True
  gather_facts: True
  roles:
    - { role: "satellite-public-hostname" }
    # - { role: "satellite-capsule-installation",   when: install_capsule }
    # - { role: "satellite-capsule-configuration",  when: configure_capsule }
    # - { role: "satellite-capsule-installation",   when: install_capsule }
    # - { role: "satellite-capsule-configuration",  when: configure_capsule }
- name: Software flight-check
  hosts: localhost
ansible/configs/satellite-vm/requirements.yml
New file
@@ -0,0 +1,4 @@
---
collections:
- name: theforeman.foreman
  version: '0.6.0'
ansible/configs/satellite-vm/software.yml
@@ -6,24 +6,40 @@
  tasks:
    - debug:
        msg: "Software tasks Started"
- name: Configuring satellite Hosts
  hosts: satellites
  become: True
  gather_facts: True
  roles:
    - { role: "satellite-public-hostname" }
    - { role: "satellite-installation",                 when: install_satellite  }
    # # - { role: "satellite-hammer-cli",                 when: install_satellite   }
    - { role: "satellite-manage-organization",          when: configure_satellite }
    - { role: "satellite-manage-manifest",              when: configure_satellite }
    - { role: "satellite-manage-subscription",          when: configure_satellite }
    - { role: "satellite-manage-sync",                  when: configure_satellite }
    # - { role: "satellite-manage-lifecycle",             when: configure_satellite }
    # - { role: "satellite-manage-content-view",          when: configure_satellite }
    # - { role: "satellite-manage-activationkey",         when: configure_satellite }
  tasks:
    - import_role:
        name: satellite-public-hostname
    - when: install_satellite
      include_role:
        name: "{{ _role }}"
      loop_control:
        loop_var: _role
      loop:
        - satellite-installation
        # - satellite-hammer-cli
    - when: configure_satellite
      include_role:
        name: "{{ _role }}"
      loop_control:
        loop_var: _role
      loop:
        - satellite-manage-organization
        - satellite-manage-manifest
        - satellite-manage-subscription
        - satellite-manage-sync
        # - satellite-manage-lifecycle
        # - satellite-manage-content-view
        # - satellite-manage-activationkey
        # - satellite-manage-capsule-certificate
- name: Software flight-check
  hosts: localhost
ansible/install_galaxy_roles.yml
@@ -26,6 +26,20 @@
        ansible-galaxy install
        -r "{{ requirements_path }}"
        -p "{{ ANSIBLE_REPO_PATH | default('.') }}/configs/{{ env_type }}/roles"
      when:
        - r_requirements_stat.stat.exists
        - r_requirements_content | length > 0
      when: >-
        r_requirements_stat.stat.exists
        and r_requirements_content | length > 0
        and ( r_requirements_content is mapping
              and 'roles' in r_requirements_content )
        or r_requirements_contet is sequence
    - name: Import collections from requirements.yml
      command: >-
        ansible-galaxy collection install
        -r "{{ requirements_path }}"
        -p "configs/{{ env_type }}/collections"
      when: >-
        r_requirements_stat.stat.exists
        and r_requirements_content | length > 0
        and r_requirements_content is mapping
        and "collections" in r_requirements_content
ansible/roles/satellite-manage-organization/README.adoc
@@ -9,19 +9,21 @@
Role: {role}
============
This role creates organization.
This role creates organization.
Requirements
------------
. Satellite must be install and setup.
. Hammer cli config must be configured/updated with privileged user and password to run the satellite cli.
. Satellite must be install and setup.
. `satellite-public-hostname` needs to run first, to set the `publicname` fact.
Role Variables
--------------
|===
|satellite_version: "Digit" |Required |satellite version
|satellite_admin: "String"  |Required |Sattelite account to use
|satellite_admin_password: "String" |Required |Password for sattelite user account
|org: "String" |Required |Organization name
|org_label: "String" |Required | Organization label in string without space
|org_description: "String" |Required | Organization description
@@ -31,7 +33,9 @@
[source=text]
----
satellite_version: 6.4
satellite_version: 6.7
satellite_admin: 'admin'
satellite_admin_password: 'changeme'
org: "gpte"
org_label: "gpte"
org_description: "Global Partner Training and Enablement"
@@ -73,7 +77,7 @@
    org_label: "gpte"
    org_description: "Global Partner Training and Enablement"
  roles:
    - satellite-manage-organization
    - satellite-manage-organization
[user@desktop ~]$ ansible-playbook playbook.yml
----
ansible/roles/satellite-manage-organization/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_organization
ansible/roles/satellite-manage-organization/tasks/version_6.x.yml
New file
@@ -0,0 +1,10 @@
---
- name: "Create CI Organization"
  theforeman.foreman.foreman_organization:
    username: "{{ satellite_admin }}"
    password: "{{ satellite_admin_password }}"
    server_url: "https://{{ publicname }}"
    name: "{{ org }}"
    label: "{{ org_label }}"
    description: "{{ org_description }}"
    state: present
tests/static/requirements.txt
@@ -1,3 +1,4 @@
# Versions are pinned to prevent pypi releases arbitrarily breaking
# tests with new APIs/semantics. We want to update versions deliberately.
ansible==2.9.5
apipy==0.5.15
tests/static/syntax-check.sh
@@ -38,13 +38,19 @@
        )
    fi
    if [ -e "${ansible_path}/configs/${env_type}/hosts" ]; then
        inventory=(-i "${ansible_path}/configs/${env_type}/hosts")
    else
        inventory=(-i "${static}/tox-inventory.txt")
    fi
    # Setup galaxy roles and collections, make sure it works
    ansible-playbook --tags galaxy_roles \
                     "${inventory[@]}" \
                     ${ansible_path}/main.yml \
                     ${extra_args[@]} \
                     -e @${i}
    for playbook in \
        ${ansible_path}/main.yml \
        ${ansible_path}/destroy.yml; do