- Deploy Cloudstack Management Server Using Ansible – Part I (MariaDB)
- Deploy Cloudstack Management Server Using Ansible – Part II (Management Server)
- Deploy Cloudstack Management Server Using Ansible – Part III (KVM Setup)
- Deploy Cloudstack Management Server Using Ansible – Part IV (Playbook)
Introduction
Hello, In this guide we’ll look at how to deploy cloudstack management server using ansible.
Before we go further, its good to have a brief introduction of Ansible.
About Ansible
Ansible is an IT configuration management and provisioning tool that enables System administrators to deploy and manage infrastructure as code.
Ansible is easy to setup. Its is agentless i.e no need to install an agent on the target host inorder to manage it. Ansible uses ssh to connect to the target hosts.
It can also do IT orchestration, where you have to run tasks in sequence and create a chain of events which must happen on several different servers or devices.
Some of the benefits of Ansible are:
- Ansible configuration is human readable and easy to understand.
- Code by convention: Structure of the code follows a convetion
- To access a target host, you do not need an agent. Access is provided via ssh
- A great, dedicated and growing community
- A host inventory handles and defines the infrastructure
Ansible is available for free and runs on Linux, Mac or BSD. Aside from the free offering, Ansible also has an enterprise product called Ansible Tower.
Ansible works by concept of Playbooks, Roles, tasks and inventories. These are the main components of an ansible playbook. Visit https://www.ansible.com/ for more details on how ansible works.
Installing Ansible
To use ansible, it must be installed on a local machine that you will use to administer remote hosts. In our case, our local machine will be a centos 7 vm.
Run the following command to install ansible
1 |
sudo yum ansible.noarch |
We don’t need any further configuration. We are good to get started.
Lets get started with Cloudstack.
Prepare the directory structure for our ansible Roles. We’ll have s Roles in this article. i.e
- Common
- Mariadb
- Management Server
- KVM Host
- NFS Server
Create the required directory tree as below. Our main directory will be called cloudstack.
cd to cloudstack directory.
1 2 3 |
mkdir -p cloudstack cd cloudstack |
Create the directories for the different roles as below
1 2 3 4 5 6 7 8 9 |
mkdir -p roles/common/{tasks,handlers,templates,files,vars,defaults,meta} mkdir -p roles/management/{tasks,handlers,templates,files,vars,defaults,meta} mkdir -p roles/mariadb/{tasks,handlers,templates,files,vars,defaults,meta} mkdir -p roles/nfs/{tasks,handlers,templates,files,vars,defaults,meta} mkdir -p roles/kvm/{tasks,handlers,templates,files,vars,defaults,meta} |
Create the main.yml files under each directory in the different roles as below
1 2 3 4 5 6 7 8 9 |
touch roles/common/{tasks,handlers,templates,files,vars,defaults,meta}/main.yml touch roles/management/{tasks,handlers,templates,files,vars,defaults,meta}/main.yml touch roles/mariadb/{tasks,handlers,templates,files,vars,defaults,meta}/main.yml touch roles/kvm/{tasks,handlers,templates,files,vars,defaults,meta}/main.yml touch roles/nfs/{tasks,handlers,templates,files,vars,defaults,meta}/main.yml |
Run tree to confirm the layout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
→ tree . └── roles ├── common │ ├── defaults │ │ └── main.yml │ ├── files │ │ └── main.yml │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ ├── templates │ │ └── main.yml │ └── vars │ └── main.yml ├── kvm │ ├── defaults │ │ └── main.yml │ ├── files │ │ └── main.yml │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ ├── templates │ │ └── main.yml │ └── vars │ └── main.yml ├── management │ ├── defaults │ │ └── main.yml │ ├── files │ │ └── main.yml │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ ├── templates │ │ └── main.yml │ └── vars │ └── main.yml ├── mariadb │ ├── defaults │ │ └── main.yml │ ├── files │ │ └── main.yml │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ ├── templates │ │ └── main.yml │ └── vars │ └── main.yml └── nfs ├── defaults │ └── main.yml ├── files │ └── main.yml ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── tasks │ └── main.yml ├── templates │ └── main.yml └── vars └── main.yml 41 directories, 35 files |
We are now ready to begin adding our code
Create and Update Inventory File
create inventory file and open it
1 2 3 |
touch inventory.yaml vim inventory.yml |
Update the inventory file as below and change where applicable
1 2 3 4 5 6 7 8 9 10 11 |
[management] cs-manager-01 ansible_host=10.31.46.61 ansible_user=root [mariadb] cs-mariadb-01 ansible_host=10.31.46.62 ansible_user=root [kvm] cs-compute-01 ansible_host=10.31.46.63 ansible_user=root [nfs] cs-nfs-01 ansible_host=10.31.46.64 ansible_user=root |
Common Role
The common role will contain task that will be applied to all the hosts. These are tasks such as Updating packages, installing common packages e.t.c
Let’s switch to tasks directory under the common role
1 |
cd roles/common/tasks |
Open the main.yml file and add the following code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
- name: Update System Packages yum: name: '*' state: latest update_cache: yes - name: Installing Common Packages yum: name: "{{ item }}" state: latest update_cache: yes with_items: - MySQL-python - libselinux-python - nfs-utils - tmux - vim - bash-completion - name: Setting SELINUX to permissive selinux: conf: '/etc/selinux/config' policy: 'targeted' state: 'permissive' |
The above code will update yum packages, install specified packages and set selinux to permissive on all the hosts.
That’s enough for the common role.
After Preparing all the nodes, we can now setup MariaDB
MariaDB Role
Switch to MariaDB default directory. Here we’ll set up our default values that will be used in this role. this will include values such as MySQL usernames, passwords, IP addresses e.t.c
Open the main.yml file and add the following content
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
--- mysql_ports: - 3306 mysql_root_username: "root" myql_cloud_user: "cloud" mysql_cloud_password: "pass1234" mysql_root_password: "pass1234" mysql_remote_password: "pass1234" cs_manager_ip: 10.31.46.61 cs_mariadb_ip: 10.31.46.62 mysql_client_hosts: - name: "{{ cs_manager_ip }}" - name: "{{ cs_mariadb_ip }}" mysql_databases: - name: cloud - name: cloud_usage mysql_users: - name: " {{ mysql_root_username }} " host: "%" password: "{{ mysql_root_password }}" priv: "cloud.*:all/cloud_usage.*:all" - name: "{{ myql_cloud_user }}" host: "%" password: "{{ mysql_cloud_password }}" priv: "cloud.*:all/cloud_usage.*:all" |
Switch to MariaDB task directory
1 |
cd mariadb/tasks |
Add the following code to the main.yml file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
- name: Installing mariadb yum: name: "{{ item }}" state: latest update_cache: no with_items: - mariadb-server - name: Ensure service is started and that it always starts on boot service: name: mariadb state: started enabled: yes - name: Ensure Services are enabled at Boot service: name: "{{ item }}" enabled: yes state: started with_items: - rpcbind - nfs-lock # Update Mysql Root Password # Comment login_user and login_password when running for the first time - name: update mysql root password mysql_user: # login_user: "{{ mysql_root_username }}" # login_password: "{{ mysql_root_password }}" name: root host: "{{ item }}" password: "{{ mysql_root_password }}" state: present with_items: - localhost - '127.0.0.1' - "{{ cs_manager_ip }}" - "{{ cs_mariadb_ip }}" - name: Add cloud user mysql_user: login_user: "{{ mysql_root_username }}" login_password: "{{ mysql_root_password }}" name: " {{ myql_cloud_user }} " host: "{{ item.name }}" password: "{{ mysql_root_password }}" state: present with_items: "{{ mysql_client_hosts }}" - name: Removing Test database mysql_db: login_user: "{{ mysql_root_username }}" login_password: "{{ mysql_root_password }}" name: test state: absent - name: Removing anonymous mysql users mysql_user: login_user: "{{ mysql_root_username }}" login_password: "{{ mysql_root_password }}" name: "" host_all: yes state: absent - name: Creating cloudstack mysql databases mysql_db: login_user: "{{ mysql_root_username }}" login_password: "{{ mysql_root_password }}" name: "{{ item.name }}" state: present with_items: "{{ mysql_databases }}" - name: create mysql users and assign privileges to db mysql_user: login_user: "{{ mysql_root_username }}" login_password: "{{ mysql_root_password }}" name: "{{ item.name }}" host: "{{ item.host | default('localhost') }}" password: "{{ item.password }}" priv: "{{ item.priv }}" state: "{{ item.state | default('present') }}" append_privs: "{{ item.append_privs | default('no') }}" with_items: "{{ mysql_users }}" - name: Allow Ports through the firewall firewalld: zone: public port: "{{ item }}/tcp" permanent: true state: enabled with_items: " {{ mysql_ports }} " |
Switch to MariaDB handlers directory and update the main.yml file as below
1 2 3 4 5 6 7 |
--- # Handlers file - name: Reload firewalld command: firewall-cmd --reload - name: restart mysql service: name=mariadb state=restarted |
Next we’ll look at Deploying the Cloudstack Management Server.
harun
Latest posts by harun (see all)
- Reset Linux Root Password Using Rescue CD - September 21, 2018
- Extending Linux Root Partition using LVM - June 14, 2018
- Parted Utility - April 11, 2018