├── tests ├── inventory ├── centos-7-test.yml ├── test.yml ├── ansible.cfg └── Dockerfile.centos-7 ├── vars ├── main.yml └── RedHat.yml ├── tasks ├── cinder_db_setup.yml ├── cinder_install_RedHat.yml ├── cinder_nova.yml ├── cinder_configure.yml ├── cinder_post_install.yml ├── main.yml └── cinder_service_setup.yml ├── meta └── main.yml ├── handlers └── main.yml ├── README.md ├── .travis.yml └── defaults └── main.yml /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for ansible-role-openstack-cinder 3 | -------------------------------------------------------------------------------- /tests/centos-7-test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # test file 3 | 4 | - hosts: localhost 5 | roles: 6 | - role_under_test 7 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # test file 3 | 4 | - hosts: all 5 | remote_user: root 6 | roles: 7 | - ansible-role-openstack-cinder 8 | -------------------------------------------------------------------------------- /tests/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = ../../ 3 | host_key_checking = False 4 | ansible_managed = Ansible managed: modified on %Y-%m-%d %H:%M:%S by {uid} on {host} 5 | -------------------------------------------------------------------------------- /tasks/cinder_db_setup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for cinder DB Setup 3 | 4 | - name: DB sync for cinder. 5 | command: cinder-manage db sync 6 | become: yes 7 | become_user: "{{ cinder_system_user_name }}" 8 | 9 | -------------------------------------------------------------------------------- /tasks/cinder_install_RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for cinder install on RedHat 3 | 4 | - name: Install OpenStack cinder packages. 5 | yum: 6 | name: "{{ item }}" 7 | state: installed 8 | with_items: "{{ cinder_packages }}" 9 | -------------------------------------------------------------------------------- /tasks/cinder_nova.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Configure cinder nova. 3 | shell: | 4 | openstack-config --set "{{ cinder_nova_config_location }}" "{{ item.section }}" "{{ item.param }}" "{{ item.value }}" 5 | with_items: 6 | - "{{ cinder_nova_config }}" 7 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | galaxy_info: 2 | author: z 3 | description: Installs and configures openstack cinder. 4 | company: 5 | license: license (BSD, MIT) 6 | min_ansible_version: 1.9 7 | platforms: 8 | - name: EL 9 | versions: 10 | - 7 11 | galaxy_tags: 12 | - cloud 13 | - cinder 14 | - openstack 15 | dependencies: [] 16 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for Redhat 3 | 4 | cinder_packages: 5 | - openstack-cinder 6 | 7 | cinder_system_service_name: 8 | - openstack-cinder-api 9 | - openstack-cinder-scheduler 10 | 11 | cinder_volume_system_service_name: 12 | - openstack-cinder-volume 13 | 14 | cinder_config_location: /etc/cinder/cinder.conf 15 | cinder_nova_config_location: /etc/nova/nova.conf 16 | -------------------------------------------------------------------------------- /tasks/cinder_configure.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Configure cinder. 3 | shell: | 4 | openstack-config --set "{{ cinder_config_location }}" "{{ item.section }}" "{{ item.param }}" "{{ item.value }}" 5 | with_items: 6 | - "{{ cinder_config }}" 7 | 8 | - name: Configure cinder use ceph. 9 | shell: | 10 | openstack-config --set "{{ cinder_config_location }}" "{{ item.section }}" "{{ item.param }}" "{{ item.value }}" 11 | with_items: 12 | - "{{ cinder_ceph_config }}" 13 | when: cinder_ceph_config 14 | 15 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for ansible-role-openstack-cinder 3 | 4 | - name: restart cinder 5 | service: 6 | name: "{{ item }}" 7 | state: restarted 8 | with_items: 9 | - "{{ cinder_system_service_name }}" 10 | 11 | - name: restart cinder volume 12 | service: 13 | name: "{{ item }}" 14 | state: restarted 15 | with_items: 16 | - "{{ cinder_volume_system_service_name }}" 17 | 18 | - name: restart nova api 19 | service: 20 | name: "{{ item }}" 21 | state: restarted 22 | with_items: 23 | - "openstack-nova-api" 24 | -------------------------------------------------------------------------------- /tasks/cinder_post_install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for openstack-cinder post install 3 | 4 | - name: Ensure openstack-cinder services is started and enabled at boot. 5 | service: 6 | name: "{{ item }}" 7 | state: started 8 | enabled: yes 9 | with_items: 10 | - "{{ cinder_system_service_name }}" 11 | notify: restart nova api 12 | 13 | 14 | - name: Ensure openstack-cinder-volume services is started and enabled at boot. 15 | service: 16 | name: "{{ item }}" 17 | state: started 18 | enabled: yes 19 | with_items: 20 | - "{{ cinder_volume_system_service_name }}" 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: openstack-cinder 2 | 3 | [![Build Status](https://travis-ci.org/devops/ansible-role-openstack-cinder.svg?branch=master)](https://travis-ci.org/devops/ansible-role-openstack-cinder) 4 | 5 | Ansible role that installs and configures openstack cinder. 6 | 7 | ## Requirements 8 | 9 | None. 10 | 11 | ## Role Variables 12 | 13 | ### `defaults/main.yml` 14 | 15 | 16 | ### `vars/RedHat.yml` 17 | 18 | 19 | ## Dependencies 20 | 21 | None. 22 | 23 | ## Example Playbook 24 | 25 | 1) Install openstack-cinder and use the default settings. 26 | 27 | - hosts: all 28 | roles: 29 | - ansible-role-openstack-cinder 30 | 31 | 32 | ## License 33 | 34 | MIT / BSD 35 | 36 | ## Author Information 37 | 38 | z. 39 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for ansible-role-openstack-cinder 3 | 4 | # Variable setup. 5 | - name: Include OS-specific variables. 6 | include_vars: "{{ item }}" 7 | with_first_found: 8 | - "{{ ansible_os_family }}.yml" 9 | - "{{ ansible_os_family | lower }}.yml" 10 | tags: 11 | - always 12 | 13 | - include: cinder_service_setup.yml 14 | run_once: True 15 | 16 | # Setup/Install tasks. 17 | - include: cinder_install_RedHat.yml 18 | when: ansible_os_family == 'RedHat' 19 | 20 | # Configure tasks. 21 | - include: cinder_configure.yml 22 | tags: 23 | - cinder-config 24 | 25 | # DB tasks. 26 | - include: cinder_db_setup.yml 27 | run_once: True 28 | tags: 29 | - cinder-db-setup 30 | 31 | # Configure nova 32 | - include: cinder_nova.yml 33 | 34 | # Finalize installation tasks. 35 | - include: cinder_post_install.yml 36 | -------------------------------------------------------------------------------- /tests/Dockerfile.centos-7: -------------------------------------------------------------------------------- 1 | FROM centos:7 2 | 3 | # Install systemd -- See https://hub.docker.com/_/centos/ 4 | RUN yum -y swap -- remove fakesystemd -- install systemd systemd-libs 5 | RUN yum -y update; yum clean all; \ 6 | (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \ 7 | rm -f /lib/systemd/system/multi-user.target.wants/*; \ 8 | rm -f /etc/systemd/system/*.wants/*; \ 9 | rm -f /lib/systemd/system/local-fs.target.wants/*; \ 10 | rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ 11 | rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ 12 | rm -f /lib/systemd/system/basic.target.wants/*; \ 13 | rm -f /lib/systemd/system/anaconda.target.wants/*; 14 | 15 | # Install Ansible 16 | RUN yum -y install epel-release 17 | RUN yum -y install git ansible sudo iproute 18 | RUN yum clean all 19 | 20 | # Install Ansible inventory file 21 | RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts 22 | 23 | VOLUME ["/sys/fs/cgroup"] 24 | CMD ["/usr/sbin/init"] 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | env: 3 | - distribution: centos 4 | version: 7 5 | init: /usr/lib/systemd/systemd 6 | run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" 7 | playbook: centos-7-test.yml 8 | 9 | services: 10 | - docker 11 | 12 | before_install: 13 | # Pull container 14 | - 'sudo docker pull ${distribution}:${version}' 15 | 16 | # Customize container 17 | - 'sudo docker build --rm=true --file=tests/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible tests' 18 | 19 | script: 20 | - container_id=$(mktemp) 21 | 22 | # Run container in detached state 23 | - 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} ${distribution}-${version}:ansible "${init}" > "${container_id}"' 24 | 25 | # Ansible syntax check. 26 | - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} --syntax-check' 27 | 28 | # Test role. 29 | - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}' 30 | 31 | # Test role idempotence. 32 | - > 33 | sudo docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} 34 | | grep -q 'changed=0.*failed=0' 35 | && (echo 'Idempotence test: pass' && exit 0) 36 | || (echo 'Idempotence test: fail' && exit 1) 37 | 38 | # Some debugging (show all the logs). 39 | - sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ss -ntlup || true 40 | 41 | # Clean up 42 | - sudo docker stop "$(cat ${container_id})" 43 | 44 | notifications: 45 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 46 | -------------------------------------------------------------------------------- /tasks/cinder_service_setup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for openstack-cinder service setup 3 | 4 | - name: Create the service credentials for cinder. 5 | shell: | 6 | openstack user create --domain default --password "{{ cinder_keystone_password }}" "{{ cinder_keystone_user }}" 7 | openstack role add --project service --user "{{ cinder_keystone_user }}" admin 8 | environment: 9 | - "{{ token_auth_env }}" 10 | 11 | - name: Create the service entity for cinder. 12 | shell: | 13 | openstack service create --name "{{ cinder_service_name }}" --description "{{ cinder_service_description }}" "{{ cinder_service_type }}" 14 | environment: 15 | - "{{ token_auth_env }}" 16 | 17 | - name: Create the service entity for cinder v2. 18 | shell: | 19 | openstack service create --name "{{ cinder_service_v2_name }}" --description "{{ cinder_service_v2_description }}" "{{ cinder_service_v2_type }}" 20 | environment: 21 | - "{{ token_auth_env }}" 22 | 23 | # Create the API endpoint for cinder. 24 | - name: Check if API endpoint exists for service "{{ cinder_service_type }}" 25 | shell: "openstack endpoint list --service {{ cinder_service_type }}" 26 | register: check_endpoint_result 27 | environment: 28 | - "{{ token_auth_env }}" 29 | ignore_errors: True 30 | 31 | - name: "Specify API endpoints for {{ cinder_service_type }} service" 32 | when: check_endpoint_result.rc == 0 33 | shell: | 34 | openstack endpoint create --region {{ cinder_service_region }} {{ cinder_service_type }} public {{ cinder_service_public_url }} 35 | openstack endpoint create --region {{ cinder_service_region }} {{ cinder_service_type }} internal {{ cinder_service_internal_url }} 36 | openstack endpoint create --region {{ cinder_service_region }} {{ cinder_service_type }} admin {{ cinder_service_admin_url }} 37 | environment: 38 | - "{{ token_auth_env }}" 39 | 40 | # Create the API endpoint for cinder v2. 41 | - name: Check if API endpoint exists for service "{{ cinder_service_v2_type }}" 42 | shell: "openstack endpoint list --service {{ cinder_service_v2_type }}" 43 | register: check_endpoint_v2_result 44 | environment: 45 | - "{{ token_auth_env }}" 46 | ignore_errors: True 47 | 48 | - name: "Specify API endpoints for {{ cinder_service_v2_type }} service" 49 | when: check_endpoint_v2_result.rc == 0 50 | shell: | 51 | openstack endpoint create --region {{ cinder_service_region }} {{ cinder_service_v2_type }} public {{ cinder_service_v2_public_url }} 52 | openstack endpoint create --region {{ cinder_service_region }} {{ cinder_service_v2_type }} internal {{ cinder_service_v2_internal_url }} 53 | openstack endpoint create --region {{ cinder_service_region }} {{ cinder_service_v2_type }} admin {{ cinder_service_v2_admin_url }} 54 | environment: 55 | - "{{ token_auth_env }}" 56 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for ansible-role-openstack-cinder 3 | 4 | ## openstack public config 5 | # openstack_controller_host: "" 6 | # openstack_keystone_auth_uri: "" 7 | # openstack_keystone_auth_url: "" 8 | # openstack_admin_vip: "" 9 | # openstack_public_vip: "" 10 | # openstack_internal_vip: "" 11 | # openstack_libvirt_secret_uuid: "" 12 | 13 | cinder_system_user_name: cinder 14 | 15 | # cinder service 16 | cinder_service_region: RegionOne 17 | 18 | ## cinder service v1 19 | cinder_service_name: cinder 20 | cinder_service_type: volume 21 | cinder_service_description: "OpenStack Block Storage" 22 | cinder_service_admin_url: "http://{{ openstack_admin_vip }}:8776/v1/%\\(tenant_id\\)s" 23 | cinder_service_internal_url: "http://{{ openstack_internal_vip }}:8776/v1/%\\(tenant_id\\)s" 24 | cinder_service_public_url: "http://{{ openstack_public_vip }}:8776/v1/%\\(tenant_id\\)s" 25 | 26 | ## cinder service v2 27 | cinder_service_v2_name: cinderv2 28 | cinder_service_v2_type: volumev2 29 | cinder_service_v2_description: "OpenStack Block Storage v2" 30 | cinder_service_v2_admin_url: "http://{{ openstack_admin_vip }}:8776/v2/%\\(tenant_id\\)s" 31 | cinder_service_v2_internal_url: "http://{{ openstack_internal_vip }}:8776/v2/%\\(tenant_id\\)s" 32 | cinder_service_v2_public_url: "http://{{ openstack_public_vip }}:8776/v2/%\\(tenant_id\\)s" 33 | 34 | # cinder db 35 | cinder_db_host: "{{ openstack_db_host }}" 36 | cinder_db_name: "cinder" 37 | cinder_db_user: "cinder" 38 | cinder_db_password: "cinder" 39 | cinder_db_priv: "{{ cinder_db_name }}.*:ALL" 40 | 41 | # cinder rabbitmq 42 | cinder_rabbitmq_host: "{{ openstack_controller_host }}" 43 | cinder_rabbitmq_userid: 'cinder' 44 | cinder_rabbitmq_password: 'cinder' 45 | cinder_rabbitmq_vhost: '/cinder' 46 | 47 | # cinder keystone 48 | cinder_keystone_user: "cinder" 49 | cinder_keystone_password: "cinder" 50 | 51 | # cinder config 52 | cinder_rpc_backend: "rabbit" 53 | cinder_auth_strategy: "keystone" 54 | cinder_lock_path: "/var/lib/cinder/tmp" 55 | cinder_my_ip: "{{ mgmt_ip }}" 56 | cinder_encryption_auth_url: "{{ openstack_keystone_auth_uri }}/v3" 57 | cinder_osapi_volume_listen: "{{ mgmt_ip }}" 58 | cinder_memcached_servers: "{{ openstack_memcached_servers }}" 59 | 60 | ## cinder rabbitmq config 61 | cinder_rabbit_hosts: "{{ openstack_rabbit_hosts | default('{{ openstack_controller_host }}')}}" 62 | cinder_rabbit_retry_interval: 1 63 | cinder_rabbit_retry_backoff: 2 64 | cinder_rabbit_max_retries: 0 65 | cinder_rabbit_durable_queues: "true" 66 | cinder_rabbit_ha_queues: "true" 67 | 68 | ## cinder ceph config 69 | cinder_rbd_pool: "cinder" 70 | cinder_rbd_ceph_conf: "/etc/ceph/ceph.conf" 71 | cinder_rbd_flatten_volume_from_snapsho: "false" 72 | cinder_rbd_max_clone_depth: 5 73 | cinder_rbd_store_chunk_size: 4 74 | cinder_rados_connect_timeout: -1 75 | cinder_glance_api_version: 2 76 | cinder_rbd_user: cinder 77 | cinder_rbd_secret_uuid: "{{ openstack_libvirt_secret_uuid }}" 78 | 79 | cinder_config: 80 | - { section: "database", param: "connection", value: "mysql+pymysql://{{ cinder_db_user }}:{{ cinder_db_password }}@{{ cinder_db_host }}/{{ cinder_db_name }}" } 81 | - { section: "DEFAULT", param: "rpc_backend", value: "{{ cinder_rpc_backend }}" } 82 | - { section: "DEFAULT", param: "auth_strategy", value: "{{ cinder_auth_strategy }}" } 83 | - { section: "DEFAULT", param: "my_ip", value: "{{ cinder_my_ip }}" } 84 | - { section: "DEFAULT", param: "osapi_volume_listen", value: "{{ cinder_osapi_volume_listen }}" } 85 | - { section: "keystone_authtoken", param: "auth_uri", value: "{{ openstack_keystone_auth_uri }}" } 86 | - { section: "keystone_authtoken", param: "auth_url", value: "{{ openstack_keystone_auth_url }}" } 87 | - { section: "keystone_authtoken", param: "memcached_servers", value: "{{ cinder_memcached_servers }}" } 88 | - { section: "keystone_authtoken", param: "auth_type", value: "password" } 89 | - { section: "keystone_authtoken", param: "project_domain_name", value: "default" } 90 | - { section: "keystone_authtoken", param: "user_domain_name", value: "default" } 91 | - { section: "keystone_authtoken", param: "project_name", value: "service" } 92 | - { section: "keystone_authtoken", param: "username", value: "{{ cinder_keystone_user }}" } 93 | - { section: "keystone_authtoken", param: "password", value: "{{ cinder_keystone_password }}" } 94 | - { section: "oslo_concurrency", param: "lock_path", value: "{{ cinder_lock_path }}" } 95 | - { section: "keymgr", param: "encryption_auth_url", value: "{{ cinder_encryption_auth_url }}" } 96 | - { section: "oslo_messaging_rabbit", param: "rabbit_userid", value: "{{ cinder_rabbitmq_userid }}" } 97 | - { section: "oslo_messaging_rabbit", param: "rabbit_password", value: "{{ cinder_rabbitmq_password }}" } 98 | - { section: "oslo_messaging_rabbit", param: "rabbit_virtual_host", value: "{{ cinder_rabbitmq_vhost }}" } 99 | - { section: "oslo_messaging_rabbit", param: "rabbit_hosts", value: "{{ cinder_rabbit_hosts }}" } 100 | - { section: "oslo_messaging_rabbit", param: "rabbit_retry_interval", value: "{{ cinder_rabbit_retry_interval }}" } 101 | - { section: "oslo_messaging_rabbit", param: "rabbit_retry_backoff", value: "{{ cinder_rabbit_retry_backoff }}" } 102 | - { section: "oslo_messaging_rabbit", param: "rabbit_max_retries", value: "{{ cinder_rabbit_max_retries }}" } 103 | - { section: "oslo_messaging_rabbit", param: "rabbit_durable_queues", value: "{{ cinder_rabbit_durable_queues }}" } 104 | - { section: "oslo_messaging_rabbit", param: "rabbit_ha_queues", value: "{{ cinder_rabbit_ha_queues }}" } 105 | 106 | cinder_ceph_config: 107 | - { section: "DEFAULT", param: "enabled_backends", value: "ceph" } 108 | - { section: "ceph", param: "volume_driver", value: "cinder.volume.drivers.rbd.RBDDriver" } 109 | - { section: "ceph", param: "rbd_pool", value: "{{ cinder_rbd_pool }}" } 110 | - { section: "ceph", param: "rbd_ceph_conf", value: "{{ cinder_rbd_ceph_conf }}" } 111 | - { section: "ceph", param: "rbd_flatten_volume_from_snapshot", value: "{{ cinder_rbd_flatten_volume_from_snapsho }}" } 112 | - { section: "ceph", param: "rbd_max_clone_depth", value: "{{ cinder_rbd_max_clone_depth }}" } 113 | - { section: "ceph", param: "rbd_store_chunk_size", value: "{{ cinder_rbd_store_chunk_size }}" } 114 | - { section: "ceph", param: "rados_connect_timeout", value: "{{ cinder_rados_connect_timeout }}" } 115 | - { section: "ceph", param: "glance_api_version", value: "{{ cinder_glance_api_version }}" } 116 | - { section: "ceph", param: "rbd_user", value: "{{ cinder_rbd_user }}" } 117 | - { section: "ceph", param: "rbd_secret_uuid", value: "{{ cinder_rbd_secret_uuid }}" } 118 | 119 | cinder_nova_config: 120 | - { section: "cinder", param: "os_region_name", value: "{{ cinder_service_region }}" } 121 | --------------------------------------------------------------------------------