{"id":394,"date":"2016-01-24T20:38:47","date_gmt":"2016-01-24T20:38:47","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=394"},"modified":"2016-01-24T20:59:55","modified_gmt":"2016-01-24T20:59:55","slug":"ansible-rolestaskmain-yml-playbook-for-glance-api-deployment","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2016\/01\/24\/ansible-rolestaskmain-yml-playbook-for-glance-api-deployment\/","title":{"rendered":"Ansible roles\/glance\/task\/main.yml playbook for Glance API Deployment"},"content":{"rendered":"<p>I am working on a project at work to deploy Keystone and Glance. I&#8217;ve currently been tasked with finishing off the glance role part of the playbook with the basic setup tasks and retrieving the basic qcow2 images for the various distributions and automatically retrieving and populating the glance API image-list. Here is how I did it;<\/p>\n<p>This is using an encrypted group_vars all vars.yml which contains sensitive password variables like GLANCE_DBPASS<\/p>\n<p>This file shows how Glance SQL database, permissions, population and images are uploaded to glance for use by openstack compute.<\/p>\n<p><a href=\"http:\/\/www.haxed.me.uk\/wp-content\/uploads\/2016\/01\/glance-api.png\" rel=\"attachment wp-att-399\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.haxed.me.uk\/wp-content\/uploads\/2016\/01\/glance-api.png\" alt=\"glance-api\" width=\"735\" height=\"513\" class=\"alignnone size-full wp-image-399\" srcset=\"https:\/\/haxed.me.uk\/wp-content\/uploads\/2016\/01\/glance-api.png 735w, https:\/\/haxed.me.uk\/wp-content\/uploads\/2016\/01\/glance-api-300x209.png 300w, https:\/\/haxed.me.uk\/wp-content\/uploads\/2016\/01\/glance-api-430x300.png 430w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/a><\/p>\n<p>File: osan\/roles\/glance\/tasks\/main.yml<\/p>\n<pre>\r\n---\r\n\r\n   - name: Create keystone database\r\n     mysql_db:\r\n        name: glance\r\n\r\n   - name: Configure database user privileges\r\n     mysql_user:\r\n       name: glance\r\n       host: \"{{ item }}\"\r\n       password: \"{{ GLANCE_DBPASS }}\"\r\n       priv: glance.*:ALL\r\n     with_items:\r\n       - \"%\"\r\n       - localhost\r\n\r\n#   - name: Set credentials to admin\r\n#   command: source admin-openrc.sh\r\n\r\n   - name: Create the Glance user service credentials\r\n     command: openstack user create --domain default --password {{ GLANCE_PASS }} glance\r\n     environment: admin_env\r\n     ignore_errors: yes\r\n\r\n   - name: Add the admin role to the glance user and service project\r\n     command: openstack role add --project service --user glance admin\r\n     environment: admin_env\r\n     ignore_errors: yes\r\n\r\n   - name: Create the glance service entity\r\n     command: openstack service create --name glance --description \"OpenStack Image service\" image\r\n     environment: admin_env\r\n     ignore_errors: yes\r\n\r\n   - name: Create the Image service API endpoints for glance\r\n     command: openstack endpoint create --region RegionOne image public http:\/\/controller:9292\r\n     environment: admin_env\r\n     ignore_errors: yes\r\n\r\n   - name: Create the Image service API endpoints for glance\r\n     command: openstack endpoint create --region RegionOne image internal http:\/\/controller:9292\r\n     environment: admin_env\r\n     ignore_errors: yes\r\n\r\n   - name: Create the Image service API endpoints for glance\r\n     command: openstack endpoint create --region RegionOne image admin 'http:\/\/controller:9292'\r\n     environment: admin_env\r\n     ignore_errors: yes\r\n\r\n   - name: Install Glance and Dependencies\r\n     yum: pkg={{item}} state=installed\r\n     with_items:\r\n     - openstack-glance\r\n     - python-glance\r\n     - python-glanceclient\r\n\r\n   - name: replace glance-api.conf file\r\n     template: src=glance-api.conf.ansible dest=\/etc\/glance\/glance-api.conf owner=root\r\n\r\n   - name: replace glance-registory.conf file\r\n     template: src=glance-registry.conf.ansible dest=\/etc\/glance\/glance-registory.conf owner=root\r\n\r\n   - name: Populate the Image service database\r\n     command: su -s \/bin\/sh -c \"glance-manage db_sync\" glance\r\n\r\n   - name: Start & Enable openstack-glance-registry.service\r\n     service: name=openstack-glance-registry.service enabled=yes state=started\r\n\r\n   - name: Start & Enable openstack-glance-api.service\r\n     service: name=openstack-glance-api.service enabled=yes state=started\r\n\r\n\r\n   - name: Retrieve CentOS 7 x86_64.qcow2\r\n     get_url: url=http:\/\/cloud.centos.org\/centos\/7\/images\/CentOS-7-x86_64-GenericCloud-1503.qcow2 dest=\/root\/CentOS-7-x86_64-GenericCloud-1503.qcow2 mode=0600\r\n\r\n   - name: Populate Glance DB with CentOS 7 qcow2 Image\r\n     command:  glance image-create --name \"centos7-x86_x64\" --file \/root\/CentOS-7-x86_64-GenericCloud-1503.qcow2 --disk-format qcow2 --container-format bare --visibility public --progress\r\n\r\n\r\n   - name: Retrieve Cirros qcow2 Image\r\n     get_url: url=http:\/\/download.cirros-cloud.net\/0.3.4\/cirros-0.3.4-x86_64-disk.img dest=\/root\/cirros-0.3.4-x86_64-disk.img mode=0600\r\n\r\n   - name: Import Cirros qcow Image to Glance\r\n     command:  glance image-create --name \"cirros-0.3.4_x86_64\" --file \/root\/cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --visibility public --progress\r\n\r\n\r\n   - name: Retrieve Ubuntu 14.04 Trusty Tahr qcow2 Image\r\n     get_url: url=http:\/\/cloud-images.ubuntu.com\/releases\/14.04\/release-20140416.1\/ubuntu-14.04-server-cloudimg-amd64-disk1.img dest=\/root\/ubuntu-14.04-server-cloudimg-amd64-disk1.img mode=0600\r\n\r\n   - name: Import Ubuntu 14.04 Trusty Tahr to Glance\r\n     command: glance image-create --name \"ubuntu-14.04-lts-trusty-tahr-amd64\" --file \/root\/ubuntu-14.04-server-cloudimg-amd64-disk1.img --disk-format qcow2 --container-format bare --visibility public --progress\r\n\r\n\r\n   - name: Retrieve Fedora 23 qcow2 Image\r\n     get_url: url=https:\/\/download.fedoraproject.org\/pub\/fedora\/linux\/releases\/23\/Cloud\/x86_64\/Images\/Fedora-Cloud-Base-23-20151030.x86_64.qcow2 dest=\/root\/Fedora-Cloud-Base-23-20151030.x86_64.qcow2 mode=0600\r\n\r\n   - name: Import Fedora 23 qcow2 Image to Glance\r\n     command: glance image-create --name \"fedora-23-amd64\" --file \/root\/Fedora-Cloud-Base-23-20151030.x86_64.qcow2 --disk-format qcow2 --container-format bare --visibility public --progress\r\n\r\n\r\n   - name: Retrieve Debian 8 amd64 qcow2 Image\r\n     get_url: url=http:\/\/cdimage.debian.org\/cdimage\/openstack\/current\/debian-8.2.0-openstack-amd64.qcow2 dest=\/root\/debian-8.2.0-openstack-amd64.qcow2 mode=0600\r\n\r\n   - name: Import Debian 8 to Glance\r\n     command: glance image-create --name \"debian8-2-0-amd64\" --file \/root\/debian-8.2.0-openstack-amd64.qcow2 --disk-format qcow2 --container-format bare --visibility public --progress\r\n\r\n\r\n   - name: Retrieve OpenSuSE 13.2 Guest Qcow2 Image\r\n     get_url: url=http:\/\/download.opensuse.org\/repositories\/Cloud:\/Images:\/openSUSE_13.2\/images\/openSUSE-13.2-OpenStack-Guest.x86_64.qcow2 dest=\/root\/openSUSE-13.2-OpenStack-Guest.x86_64.qcow2 mode=0600\r\n\r\n   - name: Import OpenSuSE 13.2 to Glance\r\n     command: glance image-create --name \"opensuse-13-2-amd64\" --file \/root\/openSUSE-13.2-OpenStack-Guest.x86_64.qcow2 --disk-format qcow2 --container-format bare --visibility public --progress\r\n\r\n<\/pre>\n<p>The above is in yaml format which is really tricky so what your syntax when using it. It is VERY sensitive.<\/p>\n<p>After this runs we are left with a nice glance image-list output. Glance is ready for compute to use the qcow2 images we associated using the openstack Glance API.<\/p>\n<pre>\r\n+--------------------------------------+------------------------------------+\r\n| ID                                   | Name                               |\r\n+--------------------------------------+------------------------------------+\r\n| f58aaed4-fda7-41b3-a0c9-e99d6c956afd | centos7-x86_x64                    |\r\n| b4c7224b-0e0d-475c-880c-f48e1c0608b2 | cirros-0.3.4_x86_64                |\r\n| 975accd5-d9bc-4485-86df-88e97e7f3237 | debian8-2-0-amd64                  |\r\n| 41e7949c-3e17-434f-8008-4551673da496 | fedora-23-amd64                    |\r\n| 092338df-6e8e-471b-93ff-07b339510636 | opensuse-13-2-amd64                |\r\n| ae707804-3dd5-474f-ab8d-3d6e855e420d | ubuntu-14.04-lts-trusty-tahr-amd64 |\r\n+--------------------------------------+------------------------------------+\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am working on a project at work to deploy Keystone and Glance. I&#8217;ve currently been tasked with finishing off the glance role part of the playbook with the basic setup tasks and retrieving the basic qcow2 images for the &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2016\/01\/24\/ansible-rolestaskmain-yml-playbook-for-glance-api-deployment\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,13,15,30,7,11,12],"tags":[],"class_list":["post-394","post","type-post","status-publish","format-standard","hentry","category-ansible","category-api","category-cloud","category-glance-api","category-management-tools","category-openstack","category-openstack-api"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=394"}],"version-history":[{"count":5,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/394\/revisions"}],"predecessor-version":[{"id":400,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/394\/revisions\/400"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}