├── vars └── main.yml ├── test.yml ├── handlers └── main.yml ├── meta └── main.yml ├── README.md ├── templates └── hosts.j2 ├── defaults └── main.yml └── tasks └── main.yml /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for ansible-role-openstack-common 3 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | - hosts: servers 2 | roles: 3 | - role: ansible-role-openstack-common 4 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for ansible-role-openstack-common 3 | 4 | - name: restart network 5 | service: name=network state=restarted 6 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: z@zstack.net 4 | description: openstack common configure 5 | company: 6 | license: license (BSD, MIT) 7 | min_ansible_version: 1.8 8 | platforms: 9 | - name: EL 10 | versions: 11 | - 7 12 | categories: 13 | - cloud 14 | - system 15 | dependencies: [] 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Role Name: openstack-common 2 | 3 | A Ansible Role for openstack common configure. 4 | 5 | ## Requirements 6 | 7 | None. 8 | 9 | ## Role Variables 10 | 11 | `defaults/main.yml` 12 | 13 | - see `defaults/main.yml` 14 | 15 | ## Dependencies 16 | 17 | None. 18 | 19 | ## Example Playbook 20 | 21 | ## License 22 | 23 | MIT / BSD 24 | 25 | ## Author Information 26 | 27 | z@zstack.net 28 | -------------------------------------------------------------------------------- /templates/hosts.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 3 | ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 4 | 5 | # controller 6 | {{ openstack_controller_host }} controller 7 | 8 | {% for host in groups['all'] %} 9 | {% if hostvars[host]['mgmt_ip'] is defined %} 10 | {{ hostvars[host]['mgmt_ip'] }} {{ hostvars[host]['host_name'] }} 11 | {% endif %} 12 | {% endfor %} 13 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file for ansible-role-openstack-common 3 | 4 | openstack_release: mitaka 5 | openstack_repos: {} 6 | # - name: centos-openstack-mitaka 7 | # description: CentOS-7 - OpenStack mitaka 8 | # baseurl: http://mirrors.aliyun.com/centos/7/cloud/$basearch/openstack-mitaka/ 9 | # gpgcheck: no 10 | # - name: centos-ceph-hammer 11 | # description: CentOS-$releasever - Ceph Hammer 12 | # baseurl: http://mirrors.aliyun.com/centos/$releasever/storage/$basearch/ceph-hammer/ 13 | # gpgcheck: no 14 | # - name: centos-qemu-ev 15 | # description: CentOS-$releasever - QEMU EV 16 | # baseurl: http://mirrors.aliyun.com/centos/$releasever/virt/$basearch/kvm-common/ 17 | # gpgcheck: no 18 | openstack_host_upgrade: True -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for ansible-role-openstack-common 3 | 4 | - name: Setup repo. 5 | yum_repository: 6 | name: "{{ item.name }}" 7 | description: "{{ item.description | default(item.name) }}" 8 | baseurl: "{{ item.baseurl }}" 9 | gpgcheck: "{{ item.gpgcheck | default('no') }}" 10 | enabled: "{{ item.enabled | default('yes') }}" 11 | file: "CentOS-OpenStack-{{ openstack_release }}" 12 | with_items: 13 | - "{{ openstack_repos }}" 14 | when: openstack_repos 15 | 16 | - name: Install OpenStack repository. 17 | yum: 18 | name: "{{ item }}" 19 | state: installed 20 | with_items: 21 | - "centos-release-openstack-{{ openstack_release }}" 22 | when: not openstack_repos 23 | 24 | - name: Upgrade the packages. 25 | command: yum upgrade -y 26 | register: upgrade 27 | when: openstack_host_upgrade 28 | 29 | - name: Reboot system if required 30 | command: shutdown -r now 'Rebooting to complete system upgrade' 31 | async: 0 32 | poll: 0 33 | ignore_errors: True 34 | when: 35 | - openstack_host_upgrade 36 | - upgrade.changed 37 | 38 | - name: Wait for Server to restart. 39 | local_action: 40 | module: wait_for 41 | port=22 42 | host="{{ ansible_ssh_host }}" 43 | delay=10 44 | timeout=900 45 | when: 46 | - openstack_host_upgrade 47 | - upgrade.changed 48 | 49 | - name: Prepare hosts file for name resolution. 50 | template: src=hosts.j2 dest=/etc/hosts 51 | 52 | - name: Install OpenStack base packages. 53 | yum: name={{ item }} state=installed 54 | with_items: 55 | - python-openstackclient 56 | - openstack-selinux 57 | - iptables 58 | - iptables-services 59 | - openstack-utils 60 | 61 | - name: Ensure base service is stopped and disabled on boot. 62 | service: name={{ item }} enabled=no state=stopped 63 | ignore_errors: True 64 | with_items: 65 | - NetworkManager 66 | - firewalld 67 | 68 | - name: Ensure base service is started and enabled on boot. 69 | service: name={{ item }} enabled=yes state=started 70 | ignore_errors: True 71 | with_items: 72 | - iptables 73 | - network 74 | 75 | - name: Configure Iptables 76 | shell: | 77 | iptables -I INPUT -s {{ openstack_internal_net }}/{{ openstack_internal_netmask }} -j ACCEPT 78 | iptables-save > /etc/sysconfig/iptables --------------------------------------------------------------------------------