From ff600a503378bcd797b186e0b6cd8e5a8593b534 Mon Sep 17 00:00:00 2001 From: stephane Date: Tue, 7 Jul 2015 13:06:02 -0700 Subject: [PATCH] Move diskimage-builder and bootable image creation to roles Break out image creation via diskimage-builder into a separate role. Also break out create-bootable-image for consistency, though it is legacy stuff that we do not expect to use in future. In addition to the above, clean up a couple of typos, etc. in the adjacent code and documentation. Implements: blueprint bifrost-deployment-image Change-Id: If3dbfa6a6b4e3f6eee9b614342dbf5bccadfbd65 --- README.rst | 8 ++- playbooks/install.yaml | 2 + playbooks/inventory/group_vars/all | 6 +- .../bifrost-create-bootable-image/README.md | 63 +++++++++++++++++ .../defaults/main.yml | 5 ++ .../meta/main.yml | 16 +++++ .../tasks/create_bootable_image.yml | 12 ++-- .../tasks/main.yml | 21 ++++++ .../roles/bifrost-create-dib-image/README.md | 69 +++++++++++++++++++ .../defaults/main.yml | 10 +++ .../bifrost-create-dib-image/meta/main.yml | 16 +++++ .../tasks/main.yml} | 6 ++ playbooks/roles/ironic-install/README.md | 19 +---- .../roles/ironic-install/defaults/main.yml | 1 - playbooks/roles/ironic-install/tasks/main.yml | 15 ---- playbooks/test-bifrost-dynamic.yaml | 2 + playbooks/test-bifrost.yaml | 2 + 17 files changed, 233 insertions(+), 40 deletions(-) create mode 100644 playbooks/roles/bifrost-create-bootable-image/README.md create mode 100644 playbooks/roles/bifrost-create-bootable-image/defaults/main.yml create mode 100644 playbooks/roles/bifrost-create-bootable-image/meta/main.yml rename playbooks/roles/{ironic-install => bifrost-create-bootable-image}/tasks/create_bootable_image.yml (80%) create mode 100644 playbooks/roles/bifrost-create-bootable-image/tasks/main.yml create mode 100644 playbooks/roles/bifrost-create-dib-image/README.md create mode 100644 playbooks/roles/bifrost-create-dib-image/defaults/main.yml create mode 100644 playbooks/roles/bifrost-create-dib-image/meta/main.yml rename playbooks/roles/{ironic-install/tasks/create_dib_image.yml => bifrost-create-dib-image/tasks/main.yml} (76%) diff --git a/README.rst b/README.rst index 9cb71bfb1..ba35b0dd7 100644 --- a/README.rst +++ b/README.rst @@ -74,7 +74,7 @@ To enable EPEL on CentOS, run:: Installation ============ -The installation is split in to two parts. +The installation is split into two parts. The first part is a bash script which lays the basic groundwork of installing Ansible itself. @@ -85,6 +85,12 @@ Edit ``./playbooks/inventory/group_vars/all`` to match your environment. - Change network_interface to match the interface that will need to service DHCP requests. - Change the ironic_db_password which is set by Ansible in MySQL and in Ironic's configuration file. +The install process builds or modifies a disk image to deploy. The following two settings (which are mutually exclusive) allow you to choose if a partition image is used or an image is created with diskimage-builder. + +create_image_via_dib: true +transform_boot_image: false + + Proxy:: if running behind the proxy. export environment variables http_proxy and https_proxy diff --git a/playbooks/install.yaml b/playbooks/install.yaml index adc17afb1..b29dd4aa9 100644 --- a/playbooks/install.yaml +++ b/playbooks/install.yaml @@ -7,6 +7,8 @@ roles: - { role: bifrost-prep-for-install, when: skip_install is not defined } - ironic-install + - { role: bifrost-create-dib-image, when: create_image_via_dib == true and transform_boot_image == false } + - { role: bifrost-create-bootable-image, when: create_image_via_dib == false and transform_boot_image == true } environment: http_proxy: "{{ lookup('env','http_proxy') }}" https_proxy: "{{ lookup('env','https_proxy') }}" diff --git a/playbooks/inventory/group_vars/all b/playbooks/inventory/group_vars/all index e39a0c406..559893303 100644 --- a/playbooks/inventory/group_vars/all +++ b/playbooks/inventory/group_vars/all @@ -27,7 +27,11 @@ deploy_ramdisk_url: "http://{{ hostvars[inventory_hostname]['ansible_' + network # due to the image creation process. deploy_image_filename: "deployment_image.qcow2" deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}" -# Transform boot image is intended for use with the Ubuntu trusty image. It makes the image bootable by ihnstalling Grub. +# Setting to utilize diskimage-builder to create a bootable image. +create_image_via_dib: true +# Transform boot image is intended for use with the Ubuntu trusty image. It makes the image bootable by installing Grub. +# Setting to prepend a partition image with a boot sector and partition table. +transform_boot_image: false node_default_network_interface: eth0 # ipv4_subnet_mask is intended for the static ipv4 address assignments. ipv4_subnet_mask: 255.255.255.0 diff --git a/playbooks/roles/bifrost-create-bootable-image/README.md b/playbooks/roles/bifrost-create-bootable-image/README.md new file mode 100644 index 000000000..534d9b609 --- /dev/null +++ b/playbooks/roles/bifrost-create-bootable-image/README.md @@ -0,0 +1,63 @@ +bifrost-create-bootable-image +============================= + +This role modifies an existing partition image to create a bootable disk image. +This role is now legacy code and will not be supported in future. + +Requirements +------------ + +This role requires: + +- Ansible 1.9 +- qemu-img +- kpartx +- The partition image must have the grub bootloader installed. + +Role Variables +-------------- + +http_boot_folder, deploy_image_filename, and deploy_image all control the final destination of the built image. + +http_boot_folder: /httpboot +deploy_image_filename: "partition_image.raw" +deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}" + +Dependencies +------------ + +None at this time. + +Example Playbook +---------------- + +- hosts: localhost + connection: local + name: "Create bootable image" + sudo: yes + gather_facts: yes + roles: + - role: bifrost-create-bootable-image + + +License +------- + +Copyright (c) 2015 Hewlett-Packard Development Company, L.P. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Author Information +------------------ + +Ironic Developers diff --git a/playbooks/roles/bifrost-create-bootable-image/defaults/main.yml b/playbooks/roles/bifrost-create-bootable-image/defaults/main.yml new file mode 100644 index 000000000..a0f1a7c66 --- /dev/null +++ b/playbooks/roles/bifrost-create-bootable-image/defaults/main.yml @@ -0,0 +1,5 @@ +--- +http_boot_folder: /httpboot +deploy_image_filename: "partition_image.raw" +deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}" + diff --git a/playbooks/roles/bifrost-create-bootable-image/meta/main.yml b/playbooks/roles/bifrost-create-bootable-image/meta/main.yml new file mode 100644 index 000000000..495dbdf43 --- /dev/null +++ b/playbooks/roles/bifrost-create-bootable-image/meta/main.yml @@ -0,0 +1,16 @@ +--- +galaxy_info: + author: Ironic Developers + description: Create bootable disk image for Bifrost + company: OpenStack + license: Apache + min_ansible_version: 1.9 + platforms: + - name: Ubuntu + versions: + - trusty + - utopic + categories: + - cloud + - cloud:openstack +dependencies: [] diff --git a/playbooks/roles/ironic-install/tasks/create_bootable_image.yml b/playbooks/roles/bifrost-create-bootable-image/tasks/create_bootable_image.yml similarity index 80% rename from playbooks/roles/ironic-install/tasks/create_bootable_image.yml rename to playbooks/roles/bifrost-create-bootable-image/tasks/create_bootable_image.yml index f56cc66a2..7f8528d25 100644 --- a/playbooks/roles/ironic-install/tasks/create_bootable_image.yml +++ b/playbooks/roles/bifrost-create-bootable-image/tasks/create_bootable_image.yml @@ -14,16 +14,16 @@ # limitations under the License. --- - name: "Extracting the raw disk image" - command: qemu-img convert -O raw "{{http_boot_folder}}/{{deploy_image_filename}}" "{{http_boot_folder}}/{{deploy_image_filename}}.raw" + command: qemu-img convert -O raw "{{deploy_image}}" "{{deploy_image}}.raw" - name: "Copying Image however with 32k of empty space at the beginning of the file." - command: dd if="{{http_boot_folder}}/{{deploy_image_filename}}.raw" of="{{http_boot_folder}}/{{deploy_image_filename}}.bootimg" seek=64 + command: dd if="{{deploy_image}}.raw" of="{{deploy_image}}.bootimg" seek=64 - name: "Creating Partition Table lining up with the copied file's contents." - shell: echo '32;' | sfdisk "{{http_boot_folder}}/{{deploy_image_filename}}.bootimg" -uB -f + shell: echo '32;' | sfdisk "{{deploy_image}}.bootimg" -uB -f - name: "Allocating one of two loopbacks" command: losetup -f register: stored_value_loopback_alpha - name: "Creating loopback connetion to new image file" - command: losetup "{{stored_value_loopback_alpha.stdout}}" "{{http_boot_folder}}/{{deploy_image_filename}}.bootimg" + command: losetup "{{stored_value_loopback_alpha.stdout}}" "{{deploy_image}}.bootimg" - name: "Forcing partition table to be re-read" command: kpartx -v -a "{{stored_value_loopback_alpha.stdout}}" # Using second loopback as for some reason /dev/mapper does not translate into a chroot cleanly when devfs is mounted @@ -64,6 +64,6 @@ - name: "Detaching first loop device" command: losetup -d "{{stored_value_loopback_alpha.stdout}}" - name: "Moving image to .oldimg" - command: mv "{{http_boot_folder}}/{{deploy_image_filename}}" "{{http_boot_folder}}/{{deploy_image_filename}}.oldimg" + command: mv "{{deploy_image}}" "{{deploy_image}}.oldimg" - name: "Moving new image into place" - command: mv "{{http_boot_folder}}/{{deploy_image_filename}}.bootimg" "{{http_boot_folder}}/{{deploy_image_filename}}" + command: mv "{{deploy_image}}.bootimg" "{{deploy_image}}" diff --git a/playbooks/roles/bifrost-create-bootable-image/tasks/main.yml b/playbooks/roles/bifrost-create-bootable-image/tasks/main.yml new file mode 100644 index 000000000..e3c7b66a5 --- /dev/null +++ b/playbooks/roles/bifrost-create-bootable-image/tasks/main.yml @@ -0,0 +1,21 @@ +# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +--- +- name: "Test if deploy image is present" + stat: path={{ deploy_image }} + register: test_image_present +- name: "Creating bootable image" + include: create_bootable_image.yml + when: test_image_present.stat.exists == true diff --git a/playbooks/roles/bifrost-create-dib-image/README.md b/playbooks/roles/bifrost-create-dib-image/README.md new file mode 100644 index 000000000..7ef78c4c6 --- /dev/null +++ b/playbooks/roles/bifrost-create-dib-image/README.md @@ -0,0 +1,69 @@ +bifrost-create-dib-image +======================== + +This role uses diskimage-builder to create a bootable disk image. + +Requirements +------------ + +This role requires: + +- Ansible 1.9 + +Role Variables +-------------- + +The dib_env_vars are settings for the diskimage-builder environment variables which allow settings to be passed to elements that are being utilized to build a disk image. More information on diskimage-builder can be found at http://git.openstack.org/cgit/openstack/diskimage-builder/. Additionally, an extra_dib_elements setting exists which is a space separated list of elements to incorporate into the image. + +dib_env_vars: + DIB_CLOUD_INIT_DATASOURCES: "ConfigDrive" + ELEMENTS_PATH: "/opt/stack/diskimage-builder/elements" +extra_dib_elements: "" + +http_boot_folder, deploy_image_filename, and deploy_image all control the final destination of the built image. + +http_boot_folder: /httpboot +deploy_image_filename: "deployment_image.qcow2" +deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}" + +dib_os_element controls which OS will be used to build the image. + +dib_os_element: "ubuntu" + +Dependencies +------------ + +dib-utils must be installed from pip for the image creation to work. + +Example Playbook +---------------- + +- hosts: localhost + connection: local + name: "Build DIB image" + sudo: yes + gather_facts: yes + roles: + - role: bifrost-create-dib-image + + +License +------- + +Copyright (c) 2015 Hewlett-Packard Development Company, L.P. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Author Information +------------------ + diff --git a/playbooks/roles/bifrost-create-dib-image/defaults/main.yml b/playbooks/roles/bifrost-create-dib-image/defaults/main.yml new file mode 100644 index 000000000..19fefce93 --- /dev/null +++ b/playbooks/roles/bifrost-create-dib-image/defaults/main.yml @@ -0,0 +1,10 @@ +--- +http_boot_folder: /httpboot +deploy_image_filename: "deployment_image.qcow2" +deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}" +dib_os_element: "ubuntu" +dib_env_vars: + DIB_CLOUD_INIT_DATASOURCES: "ConfigDrive" + ELEMENTS_PATH: "/opt/stack/diskimage-builder/elements" +# extra_dib_elements is a space separated list of elements. +extra_dib_elements: "" diff --git a/playbooks/roles/bifrost-create-dib-image/meta/main.yml b/playbooks/roles/bifrost-create-dib-image/meta/main.yml new file mode 100644 index 000000000..5bf3a7fa4 --- /dev/null +++ b/playbooks/roles/bifrost-create-dib-image/meta/main.yml @@ -0,0 +1,16 @@ +--- +galaxy_info: + author: Ironic Developers + description: Create image with diskimage-builder for Bifrost + company: OpenStack + license: Apache + min_ansible_version: 1.9 + platforms: + - name: Ubuntu + versions: + - trusty + - utopic + categories: + - cloud + - cloud:openstack +dependencies: [] diff --git a/playbooks/roles/ironic-install/tasks/create_dib_image.yml b/playbooks/roles/bifrost-create-dib-image/tasks/main.yml similarity index 76% rename from playbooks/roles/ironic-install/tasks/create_dib_image.yml rename to playbooks/roles/bifrost-create-dib-image/tasks/main.yml index 482c50cf0..09bdcafcf 100644 --- a/playbooks/roles/ironic-install/tasks/create_dib_image.yml +++ b/playbooks/roles/bifrost-create-dib-image/tasks/main.yml @@ -13,6 +13,12 @@ # See the License for the specific language governing permissions and # limitations under the License. --- +# If attempting to utilize a base Ubuntu image, diskimage-builder +# is the recommended, and default path. +- name: "Test if deploy image is present" + stat: path={{ deploy_image }} + register: test_image_present - name: "Initiate image build" shell: disk-image-create -a amd64 -o "{{http_boot_folder}}/{{deploy_image_filename}}" -t qcow2 "{{dib_os_element}}" vm serial-console cloud-init-datasources "{{ extra_dib_elements}}" environment: dib_env_vars + when: test_image_present.stat.exists == false diff --git a/playbooks/roles/ironic-install/README.md b/playbooks/roles/ironic-install/README.md index 1a441046e..7a4261e6e 100644 --- a/playbooks/roles/ironic-install/README.md +++ b/playbooks/roles/ironic-install/README.md @@ -1,7 +1,7 @@ -Role Name +ironic-install ========= -This role installs a standalone ironic deployment with all required substrate in order for it to be utilized, including MySQL, RabbitMQ, dnsmasq, nginx. Additionally, it utilizes diskimage-builder to create a bootable disk image. +This role installs a standalone ironic deployment with all required substrate in order for it to be utilized, including MySQL, RabbitMQ, dnsmasq, nginx. Requirements ------------ @@ -15,8 +15,6 @@ Internet access was originally a requirement but no longer is. See doc/source/o Role Variables -------------- -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. - Testing mode is intended to help facilitate testing of the Bifrost roles and Ironic by utilizing virtual machines on the localhost and the agent_ssh driver. This variable should be set globally for playbooks utilizing the install-ironic role. testing: false @@ -30,18 +28,6 @@ The Ironic python client and shade libraries can be installed directly from GIT. ironicclient_source_install: false shade_source_install: false -The dib_env_vars are settings for the diskimage-builder environment variables which allow settings to be passed to elements that are being utilized to build a disk image. More information on diskimage-builder can be found at http://git.openstack.org/cgit/openstack/diskimage-builder/. Additionally, an extra_dib_elements setting exists which is a space separated list of elements to incorporate into the image. - -dib_env_vars: - DIB_CLOUD_INIT_DATASOURCES: "ConfigDrive" - ELEMENTS_PATH: "/opt/stack/diskimage-builder/elements" -extra_dib_elements: "" - -As for controlling if a partition image is utilized or an image is created with diskimage-builder, the following two settings which are mutually exclusive, can allow a user to choose which logic is utilized. - -create_image_via_dib: true -transform_boot_image: false - By default this role installs dnsmasq to act as a DHCP server for provisioning hosts. In the event this is not required, set the following configuration: include_dhcp_server: false @@ -87,3 +73,4 @@ limitations under the License. Author Information ------------------ +Ironic Developers diff --git a/playbooks/roles/ironic-install/defaults/main.yml b/playbooks/roles/ironic-install/defaults/main.yml index 72077b996..f900b9899 100644 --- a/playbooks/roles/ironic-install/defaults/main.yml +++ b/playbooks/roles/ironic-install/defaults/main.yml @@ -28,7 +28,6 @@ deploy_kernel_upstream_url: http://tarballs.openstack.org/ironic-python-agent/co deploy_ramdisk_url: "http://{{ hostvars[inventory_hostname]['ansible_' + network_interface]['ipv4']['address'] }}:{{nginx_port}}/coreos_production_pxe_image-oem.cpio.gz" deploy_ramdisk_upstream_url: http://tarballs.openstack.org/ironic-python-agent/coreos/files/coreos_production_pxe_image-oem.cpio.gz deploy_image_filename: "deployment_image.qcow2" -deploy_image_upstream_url: http://cloud-images.ubuntu.com/releases/trusty/release/ubuntu-14.04-server-cloudimg-amd64.tar.gz deploy_image: "{{http_boot_folder}}/{{deploy_image_filename}}" # Use cirros instead of building an image via diskimage-builder use_cirros: false diff --git a/playbooks/roles/ironic-install/tasks/main.yml b/playbooks/roles/ironic-install/tasks/main.yml index 9e2a93239..8949449e9 100644 --- a/playbooks/roles/ironic-install/tasks/main.yml +++ b/playbooks/roles/ironic-install/tasks/main.yml @@ -209,21 +209,6 @@ - name: "Download cirros to use for deployment if requested" get_url: url={{ cirros_deploy_image_upstream_url }} dest="{{ deploy_image }}" when: "{{use_cirros|bool}}" -- name: "Test if deploy image is present" - stat: path={{ deploy_image }} - register: test_os_image_present - # Create bootable image takes a partition image, prepends space for a - # bootloader, partition table, and then installs the bootloader. - # - # If attempting to utilize a base Ubuntu image, diskimage-builder - # is the recommended, and default path. -- name: "Creating bootable image" - include: create_bootable_image.yml - when: test_os_image_present.stat.exists == false and transform_boot_image == true and create_image_via_dib == false - # DIB is presently the default path. -- name: "Creating image via disk image builder" - include: create_dib_image.yml - when: test_os_image_present.stat.exists == false and transform_boot_image == false and create_image_via_dib == true - name: "Explicitly permit nginx port (TCP) for file downloads from nodes to be provisioned" command: iptables -I INPUT -p tcp --dport {{nginx_port}} -i {{network_interface}} -j ACCEPT - name: "Explicitly permit TCP/6385 for IPA callback" diff --git a/playbooks/test-bifrost-dynamic.yaml b/playbooks/test-bifrost-dynamic.yaml index 0e3d0d4de..7e445de62 100644 --- a/playbooks/test-bifrost-dynamic.yaml +++ b/playbooks/test-bifrost-dynamic.yaml @@ -50,6 +50,8 @@ - role: ironic-install cleaning: false testing: true + - { role: bifrost-create-dib-image, when: create_image_via_dib == true and transform_boot_image == false } + - { role: bifrost-create-bootable-image, when: create_image_via_dib == false and transform_boot_image == true } environment: http_proxy: "{{ lookup('env','http_proxy') }}" https_proxy: "{{ lookup('env','https_proxy') }}" diff --git a/playbooks/test-bifrost.yaml b/playbooks/test-bifrost.yaml index 288b0f6b4..d78569b90 100644 --- a/playbooks/test-bifrost.yaml +++ b/playbooks/test-bifrost.yaml @@ -34,6 +34,8 @@ - role: ironic-install cleaning: false testing: true + - { role: bifrost-create-dib-image, when: create_image_via_dib == true and transform_boot_image == false } + - { role: bifrost-create-bootable-image, when: create_image_via_dib == false and transform_boot_image == true } - role: ironic-enroll testing: true - role: bifrost-validate-host-for-deploy