Execute service setup against a delegated host using Ansible built-in modules

In order to reduce the packages required to pip install on to the hosts,
we allow the service setup to be delegated to a specific host, defaulting
to the deploy host. We also switch as many tasks as possible to using the
built-in Ansible modules which make use of the shade library.

The 'virtualenv' package is now installed appropriately by the openstack_hosts
role, so there's no need to install it any more. The 'httplib2' package is a
legacy Ansible requirement for the get_url/get_uri module which is no longer
needed. The keystone/glance/cinder client libraries are not required any more
now that we're using the upstream modules. As there are no required packages
left, the task to install them is also removed.

Depends-On: https://review.openstack.org/582359
Depends-On: https://review.openstack.org/582579
Depends-On: https://review.openstack.org/582957
Depends-On: https://review.openstack.org/583430
Change-Id: Id3b9d57981006d3f7abbb94af5f72214db3da6cb
This commit is contained in:
Jesse Pretorius 2018-07-12 17:31:42 +01:00 committed by Jesse Pretorius (odyssey4me)
parent e539056dc1
commit 5678153fa9
7 changed files with 185 additions and 165 deletions

View File

@ -16,6 +16,11 @@
## Verbosity Options ## Verbosity Options
debug: False debug: False
# Set the host which will execute the shade modules
# for the service setup. The host must already have
# clouds.yaml properly configured.
magnum_service_setup_host: "{{ openstack_service_setup_host | default('localhost') }}"
# Set the package install state for distribution and pip packages # Set the package install state for distribution and pip packages
# Options are 'present' and 'latest' # Options are 'present' and 'latest'
magnum_package_state: "latest" magnum_package_state: "latest"
@ -118,13 +123,11 @@ magnum_glance_images: []
# distro: fedora-atomic #Value for the os_distro metadata # distro: fedora-atomic #Value for the os_distro metadata
# checksum: "sha1:dab00359cfa5cd393f0a6044f77c4a78c6167a47" # checksum: "sha1:dab00359cfa5cd393f0a6044f77c4a78c6167a47"
magnum_requires_pip_packages: # Set the directory where the downloaded images will be stored
- httplib2 # on the magnum_service_setup_host host. If the host is localhost,
- python-glanceclient # then the user running the playbook must have access to it.
- python-keystoneclient magnum_image_path: "{{ lookup('env', 'HOME') }}/openstack-ansible/magnum"
- pyyaml magnum_image_path_owner: "{{ lookup('env', 'USER') }}"
- shade
- virtualenv
magnum_pip_packages: magnum_pip_packages:
- magnum - magnum

View File

@ -0,0 +1,22 @@
---
features:
- |
The service setup in keystone for magnum will now be executed
through delegation to the ``magnum_service_setup_host`` which,
by default, is ``localhost`` (the deploy host). Deployers can
opt to rather change this to the utility container by implementing
the following override in ``user_variables.yml``.
.. code-block:: yaml
magnum_service_setup_host: "{{ groups['utility_all'][0] }}"
- |
Instead of downloading images to the magnum API servers, the
images will now download to the ``magnum_service_setup_host`` to
the folder set in ``magnum_image_path`` owned by
``magnum_image_path_owner``.
deprecations:
- |
The variable ``magnum_requires_pip_packages`` is no longer required
and has therefore been removed.

View File

@ -33,19 +33,6 @@
{% endfor %} {% endfor %}
when: magnum_developer_mode | bool when: magnum_developer_mode | bool
- name: Install requires pip packages
pip:
name: "{{ magnum_requires_pip_packages }}"
state: "{{ magnum_pip_package_state }}"
extra_args: >-
{{ magnum_developer_mode | ternary(pip_install_developer_constraints | default('--constraint /opt/developer-pip-constraints.txt'), '') }}
{{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }}
{{ pip_install_options | default('') }}
register: install_packages
until: install_packages is success
retries: 5
delay: 2
- name: Retrieve checksum for venv download - name: Retrieve checksum for venv download
uri: uri:
url: "{{ magnum_venv_download_url | replace('tgz', 'checksum') }}" url: "{{ magnum_venv_download_url | replace('tgz', 'checksum') }}"

View File

@ -37,26 +37,3 @@
config_type: "ini" config_type: "ini"
notify: notify:
- Restart magnum services - Restart magnum services
- name: Download magnum images
get_url:
url: "{{ item.file }}"
dest: "/var/tmp/{{ item.file | basename }}"
checksum: "{{ item.checksum | default(omit) }}"
with_items: "{{ magnum_glance_images }}"
when: inventory_hostname == groups['magnum_all'][0]
- name: Upload images to Glance
os_image:
cloud: default
endpoint_type: internal
validate_certs: "{{ keystone_service_internaluri_insecure | ternary(false, true) }}"
name: "{{ item.name }}"
disk_format: "{{ item.disk_format }}"
container_format: "{{ item.image_format }}"
is_public: "{{ item.public }}"
filename: "/var/tmp/{{ item.file | basename }}"
properties:
os_distro: "{{ item.distro }}"
with_items: "{{ magnum_glance_images }}"
when: inventory_hostname == groups['magnum_all'][0]

View File

@ -13,130 +13,160 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
- name: Ensure the service for Magnum exists # We set the python interpreter to the ansible runtime venv if
keystone: # the delegation is to localhost so that we get access to the
command: "ensure_service" # appropriate python libraries in that venv. If the delegation
endpoint: "{{ keystone_service_adminurl }}" # is to another host, we assume that it is accessible by the
login_user: "{{ keystone_admin_user_name }}" # system python instead.
login_password: "{{ keystone_auth_admin_password }}" - name: Setup the service
login_project_name: "{{ keystone_admin_tenant_name }}" delegate_to: "{{ magnum_service_setup_host }}"
insecure: "{{ keystone_service_adminuri_insecure }}" vars:
service_name: "{{ magnum_service_name }}" ansible_python_interpreter: >-
service_type: "{{ magnum_service_type }}" {{ (magnum_service_setup_host == 'localhost') | ternary(ansible_playbook_python, ansible_python['executable']) }}
description: "{{ magnum_service_description }}" block:
register: add_magnum_service - name: Add service to the keystone service catalog
until: add_magnum_service is success os_keystone_service:
retries: 5 cloud: default
delay: 2 state: present
no_log: True name: "{{ magnum_service_name }}"
service_type: "{{ magnum_service_type }}"
description: "{{ magnum_service_description }}"
endpoint_type: admin
verify: "{{ not keystone_service_adminuri_insecure }}"
register: add_service
until: add_service is success
retries: 5
delay: 10
- name: Ensure the magnum user exists - name: Add service user
keystone: os_user:
command: "ensure_user" cloud: default
endpoint: "{{ keystone_service_adminurl }}" state: present
login_user: "{{ keystone_admin_user_name }}" name: "{{ magnum_service_user_name }}"
login_password: "{{ keystone_auth_admin_password }}" password: "{{ magnum_service_password }}"
login_project_name: "{{ keystone_admin_tenant_name }}" domain: default
insecure: "{{ keystone_service_adminuri_insecure }}" default_project: "{{ magnum_service_project_name }}"
user_name: "{{ magnum_service_user_name }}" endpoint_type: admin
tenant_name: "{{ magnum_service_project_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
password: "{{ magnum_service_password |default('changeme') }}" register: add_service_user
register: add_magnum_user until: add_service_user is success
until: add_magnum_user is success retries: 5
retries: 5 delay: 10
delay: 2 no_log: True
no_log: True
- name: Ensure the magnum user has the admin role - name: Add service user to admin roles
keystone: os_user_role:
command: "ensure_user_role" cloud: default
endpoint: "{{ keystone_service_adminurl }}" state: present
login_user: "{{ keystone_admin_user_name }}" user: "{{ magnum_service_user_name }}"
login_password: "{{ keystone_auth_admin_password }}" role: "{{ item }}"
login_project_name: "{{ keystone_admin_tenant_name }}" project: "{{ magnum_service_project_name }}"
user_name: "{{ magnum_service_user_name }}" endpoint_type: admin
tenant_name: "{{ magnum_service_project_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
role_name: "{{ item }}" register: add_service_user_role
insecure: "{{ keystone_service_adminuri_insecure }}" until: add_service_user_role is success
register: ensure_magnum_roles retries: 5
until: ensure_magnum_roles is success delay: 10
retries: 5 with_items: "{{ magnum_service_role_names }}"
delay: 2
with_items: "{{ magnum_service_role_names }}"
no_log: True
- name: Ensure the magnum endpoint is registered - name: Add endpoints to keystone endpoint catalog
keystone: os_keystone_endpoint:
command: "ensure_endpoint" cloud: default
endpoint: "{{ keystone_service_adminurl }}" state: present
login_user: "{{ keystone_admin_user_name }}" service: "{{ magnum_service_name }}"
login_password: "{{ keystone_auth_admin_password }}" endpoint_interface: "{{ item.interface }}"
login_project_name: "{{ keystone_admin_tenant_name }}" url: "{{ item.url }}"
insecure: "{{ keystone_service_adminuri_insecure }}" region: "{{ magnum_service_region }}"
region_name: "{{ magnum_service_region }}" endpoint_type: admin
service_name: "{{ magnum_service_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
service_type: "{{ magnum_service_type }}" register: add_service_endpoints
endpoint_list: until: add_service_endpoints is success
- url: "{{ magnum_service_publicurl }}" retries: 5
interface: "public" delay: 10
- url: "{{ magnum_service_internalurl }}" with_items:
interface: "internal" - interface: "public"
- url: "{{ magnum_service_adminurl }}" url: "{{ magnum_service_publicurl }}"
interface: "admin" - interface: "internal"
register: add_magnum_endpoints url: "{{ magnum_service_internalurl }}"
until: add_magnum_endpoints is success - interface: "admin"
retries: 5 url: "{{ magnum_service_adminurl }}"
delay: 2
no_log: True
- name: Ensure the magnum trustee domain exists - name: Add trustee domain
keystone: os_keystone_domain:
command: "ensure_domain" cloud: default
endpoint: "{{ keystone_service_adminurl }}" state: present
login_user: "{{ keystone_admin_user_name }}" name: "{{ magnum_trustee_domain_name }}"
login_password: "{{ keystone_auth_admin_password }}" endpoint_type: admin
login_project_name: "{{ keystone_admin_tenant_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
insecure: "{{ keystone_service_adminuri_insecure }}" register: add_trustee_domain
domain_name: "{{ magnum_trustee_domain_name }}" until: add_trustee_domain is success
domain_enabled: true retries: 5
register: add_magnum_trustee_user delay: 10
until: add_magnum_trustee_user is success
retries: 5
delay: 2
no_log: True
- name: Ensure the magnum trustee user exists - name: Add trustee user
keystone: os_user:
command: "ensure_user" cloud: default
endpoint: "{{ keystone_service_adminurl }}" state: present
login_user: "{{ keystone_admin_user_name }}" name: "{{ magnum_trustee_domain_admin_name }}"
login_password: "{{ keystone_auth_admin_password }}" password: "{{ magnum_trustee_password }}"
login_project_name: "{{ keystone_admin_tenant_name }}" domain: "{{ magnum_trustee_domain_name }}"
insecure: "{{ keystone_service_adminuri_insecure }}" default_project: "{{ magnum_service_project_name }}"
user_name: "{{ magnum_trustee_domain_admin_name }}" endpoint_type: admin
domain_name: "{{ magnum_trustee_domain_name }}" verify: "{{ not keystone_service_adminuri_insecure }}"
project_name: "{{ magnum_service_project_name }}" register: add_trustee_user
password: "{{ magnum_trustee_password |default('changeme') }}" until: add_trustee_user is success
register: add_magnum_trustee_user retries: 5
until: add_magnum_trustee_user is success delay: 10
retries: 5 no_log: True
delay: 2
no_log: True
- name: Ensure the magnum user has the admin role - name: Add trustee user to trustee domain admin roles
keystone: os_user_role:
command: "ensure_user_role" cloud: default
endpoint: "{{ keystone_service_adminurl }}" state: present
login_user: "{{ keystone_admin_user_name }}" user: "{{ magnum_trustee_domain_admin_name }}"
login_password: "{{ keystone_auth_admin_password }}" role: "{{ item }}"
login_project_name: "{{ keystone_admin_tenant_name }}" domain: "{{ add_trustee_domain.id }}"
user_name: "{{ magnum_trustee_domain_admin_name }}" endpoint_type: admin
role_name: "{{ item }}" verify: "{{ not keystone_service_adminuri_insecure }}"
domain_name: "{{ magnum_trustee_domain_name }}" register: add_trustee_role
insecure: "{{ keystone_service_adminuri_insecure }}" until: add_trustee_role is success
register: ensure_magnum_trustee_roles retries: 5
until: ensure_magnum_trustee_roles is success delay: 10
retries: 5 with_items: "{{ magnum_trustee_domain_admin_roles }}"
delay: 2
with_items: "{{ magnum_trustee_domain_admin_roles }}" - name: Create image download directory
no_log: True file:
path: "{{ magnum_image_path }}"
state: directory
mode: "0750"
owner: "{{ magnum_image_path_owner }}"
- name: Download images
get_url:
url: "{{ item.file }}"
dest: "{{ magnum_image_path }}/{{ item.file | basename }}"
checksum: "{{ item.checksum | default(omit) }}"
register: download_image
until: download_image is success
retries: 5
delay: 10
with_items: "{{ magnum_glance_images }}"
- name: Upload images to Glance
os_image:
cloud: default
state: present
endpoint_type: admin
verify: "{{ not keystone_service_adminuri_insecure }}"
name: "{{ item.name }}"
disk_format: "{{ item.disk_format }}"
container_format: "{{ item.image_format }}"
is_public: "{{ item.public }}"
filename: "{{ magnum_image_path }}/{{ item.file | basename }}"
properties:
os_distro: "{{ item.distro }}"
register: upload_image
until: upload_image is success
retries: 5
delay: 10
with_items: "{{ magnum_glance_images }}"

View File

@ -15,6 +15,7 @@
- name: Install haproxy - name: Install haproxy
hosts: localhost hosts: localhost
connection: local
become: true become: true
roles: roles:
- role: "haproxy_server" - role: "haproxy_server"

View File

@ -15,7 +15,7 @@
- name: Install magnum server - name: Install magnum server
hosts: magnum_all hosts: magnum_all
user: root remote_user: root
vars_files: vars_files:
- common/test-vars.yml - common/test-vars.yml
roles: roles: