{"id":209,"date":"2018-10-17T05:58:53","date_gmt":"2018-10-17T05:58:53","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/manage-your-openstack-cloud-with-ansible-day-two-operations\/"},"modified":"2018-10-17T05:58:53","modified_gmt":"2018-10-17T05:58:53","slug":"manage-your-openstack-cloud-with-ansible-day-two-operations","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/manage-your-openstack-cloud-with-ansible-day-two-operations\/","title":{"rendered":"Manage your OpenStack cloud with Ansible: Day two operations"},"content":{"rendered":"<p>Managing an application on OpenStack presents a host of challenges for the system administrator, and finding ways to reduce complexity and produce consistency are key ingredients to achieving success. By using Ansible, an agentless IT automation technology, a system administrator can create <a href=\"https:\/\/opensource.com\/article\/18\/8\/ansible-playbooks-you-should-try\" target=\"_blank\">Ansible playbooks<\/a> that provide consistency and reduce complexity.<\/p>\n<p>OpenStack provides a rich API to manage resources that has led to the creation of dozens of Ansible modules that can easily fit into any automation workflow. Combined with the ability to automate tasks in OpenStack instances, an operator can work both <em>inside<\/em> and <em>out<\/em> to coordinate complex operations against an environment.<\/p>\n<p>&#8220;Day one&#8221; operations refer to tasks that are executed during the initial configuration and deployment of an environment. The index of <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/modules\/list_of_cloud_modules.html#openstack\" target=\"_blank\">OpenStack modules for Ansible<\/a> lists many of the common modules used to complete tasks during day one. Creating all manner of resources, such as networks, volumes, and instances are covered. &#8220;Day two&#8221; deals with what happens next:<\/p>\n<ul>\n<li>How will upgrades happen?<\/li>\n<li>How are backups maintained?<\/li>\n<li>How does the environment scale up with demand?<\/li>\n<\/ul>\n<p>Ansible can easily handle these use cases.<\/p>\n<p>For example, consider a cluster of web servers that need to be upgraded, all sitting behind an OpenStack load balancer. With the ability to manage both the infrastructure and tasks within the VMs themselves, an operator can ensure the sequence of events executed always happens in a particular order. Here is a simple example of a playbook to perform a rolling upgrade:<\/p>\n<p>&#8211; hosts: web<br \/>\n gather_facts: true<br \/>\n user: centos<br \/>\n serial: 1 # ensures only one server will update\/reboot at a time<br \/>\n tasks:<br \/>\n &#8211; name: check for pending updates<br \/>\n yum:<br \/>\n list: updates<br \/>\n register: yum_update # check if there are updates before going any further<br \/>\n &#8211; block: <br \/>\n &#8211; name: remove web server from pool<br \/>\n os_member:<br \/>\n state: absent<br \/>\n name: &#8216;{{ ansible_hostname }}&#8217;<br \/>\n pool: weblb_80_pool<br \/>\n delegate_to: localhost<br \/>\n &#8211; name: update packages<br \/>\n package:<br \/>\n name: &#8216;*&#8217;<br \/>\n state: latest<br \/>\n become: true<br \/>\n &#8211; name: reboot server<br \/>\n shell: sleep 5 &amp;&amp; reboot &amp;<br \/>\n async: 1<br \/>\n poll: 0<br \/>\n &#8211; name: wait for server<br \/>\n wait_for_connection:<br \/>\n connect_timeout: 20<br \/>\n sleep: 5<br \/>\n delay: 5<br \/>\n timeout: 600<br \/>\n become: true<br \/>\n &#8211; name: put server back in pool<br \/>\n os_member:<br \/>\n state: present<br \/>\n name: &#8216;{{ ansible_hostname }}&#8217;<br \/>\n pool: weblb_80_pool<br \/>\n address: &#8216;{{ ansible_default_ipv4.address }}&#8217;<br \/>\n protocol_port: 80<br \/>\n delegate_to: localhost<br \/>\n when:<br \/>\n &#8211; yum_update.results | length &gt; 0 # only execute the block if there are updates<\/p>\n<p>This playbook first checks to see whether there are any updates to apply. If so, the playbook removes the node from the pool, applies the updates, and reboots the node. Once the node is back online, it gets added back into the pool. The Ansible playbook uses the <em>serial<\/em> keyword to ensure only one node is removed from the pool at a time.<\/p>\n<p>If a database is running in the OpenStack cloud, occasionally a backup will have to be restored\u2014either to refresh some test data or perhaps in the event of a data corruption incident. Orchestrating tasks between the database server and Cinder is easily accomplished with Ansible:<\/p>\n<p>&#8211; hosts: db<br \/>\n gather_facts: true<br \/>\n user: centos<br \/>\n tasks:<br \/>\n &#8211; name: stop database<br \/>\n systemd:<br \/>\n name: mongod<br \/>\n state: stopped<br \/>\n become: true<br \/>\n &#8211; name: unmount db volume<br \/>\n mount:<br \/>\n path: \/var\/lib\/mongodb<br \/>\n state: unmounted<br \/>\n become: true<br \/>\n &#8211; name: detach volume from server<br \/>\n os_server_volume: <br \/>\n state: absent<br \/>\n server: db0<br \/>\n volume: dbvol<br \/>\n delegate_to: localhost<br \/>\n &#8211; name: restore cinder backup<br \/>\n command: openstack volume backup restore dbvol_backup dbvol<br \/>\n delegate_to: localhost<br \/>\n register: vol_restore<br \/>\n failed_when:<br \/>\n &#8211; vol_restore.rc &gt; 0<br \/>\n &#8211; &#8220;&#8216;VolumeBackupsRestore&#8217; not in vol_restore.stderr&#8221;<br \/>\n &#8211; name: wait for restore to finish<br \/>\n command: openstack volume show -c status -f value dbvol<br \/>\n register: restore_progress<br \/>\n until: restore_progress.stdout is search(&#8220;available&#8221;)<br \/>\n retries: 60<br \/>\n delay: 5<br \/>\n delegate_to: localhost<br \/>\n &#8211; name: reattach volume to server<br \/>\n os_server_volume: <br \/>\n state: present<br \/>\n server: db0<br \/>\n volume: dbvol<br \/>\n device: \/dev\/vdb<br \/>\n delegate_to: localhost<br \/>\n &#8211; name: mount db volume<br \/>\n mount:<br \/>\n path: \/var\/lib\/mongodb<br \/>\n state: mounted<br \/>\n src: LABEL=dbvol<br \/>\n fstype: xfs<br \/>\n become: true<br \/>\n &#8211; name: start database<br \/>\n systemd:<br \/>\n name: mongod<br \/>\n state: started<br \/>\n become: true<\/p>\n<p>Looking closely at the playbook, you may have noticed that the restore is done via the OpenStack command line and not a proper Ansible module. In some cases, a module for a task might not exist, but Ansible is flexible enough to allow calling arbitrary commands within a playbook until a module is developed. Feel like you could write the missing module? Consider creating it by <a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/community\/index.html\" target=\"_blank\">contributing to the Ansible project<\/a>.<\/p>\n<p>These are just a couple of day-two operations a system administrator may need to orchestrate in their cloud. Roger Lopez and I will offer a <a href=\"https:\/\/www.openstack.org\/summit\/berlin-2018\/summit-schedule\/events\/21923\/simplifying-day-two-operations-with-ansible-a-hands-on-lab\" target=\"_blank\">hands-on lab<\/a> at <a href=\"https:\/\/www.openstack.org\/summit\/berlin-2018\/\" target=\"_blank\">OpenStack Summit<\/a> in Berlin with real-world scenarios and associated Ansible playbooks to automate them. We&#8217;ll also upload our examples and materials to <a href=\"https:\/\/github.com\/RHsyseng\/day-two-openstack\" target=\"_blank\">GitHub<\/a> the week of the conference for the benefit of anyone who can&#8217;t attend. <\/p>\n<p><em>Roger Lopez and David Critch will present <a href=\"https:\/\/www.openstack.org\/summit\/berlin-2018\/summit-schedule\/events\/21923\/simplifying-day-two-operations-with-ansible-a-hands-on-lab\" target=\"_blank\">Simplifying Day Two Operations with Ansible (A Hands-on Lab)<\/a> at the <a href=\"https:\/\/www.openstack.org\/summit\/berlin-2018\/\" target=\"_blank\">OpenStack Summit<\/a>, November 13-15 in Berlin.<\/em><\/p>\n<p> <a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=261765\" target=\"_blank\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Managing an application on OpenStack presents a host of challenges for the system administrator, and finding ways to reduce complexity and produce consistency are key ingredients to achieving success. By using Ansible, an agentless IT automation technology, a system administrator can create Ansible playbooks that provide consistency and reduce complexity. OpenStack provides a rich API &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/manage-your-openstack-cloud-with-ansible-day-two-operations\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Manage your OpenStack cloud with Ansible: Day two operations&#8221;<\/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":[1],"tags":[],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":0,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}