Red Hat blog
Microsoft loves Linux. But this wasn't always the case as host Saron Yitbarek will share in episodes 1 and 2 of Command Line Heroes, an original podcast from Red Hat airing January 16th, about the OS wars for the desktop and then the datacenter.
Yet, today, here we are talking about Microsoft's embrace of Linux. Nothing showcases this new approach forward than the growing relationship between Microsoft and Red Hat. In this post we're going to explore one aspect of that relationship--Microsoft SQL Server 2017 on Red Hat® Enterprise Linux®, Microsoft’s reference Linux platform. By using Ansible playbooks and roles to quickly deploy SQL Server, we get to take the best of these tools for a spin.
What is Ansible
Ansible is a simple, powerful, and agentless automation language that allows us to perform a task–like installing, configuring, and dropping in a database schema–within a matter of minutes. This Red Hat-sponsored community project is particularly powerful because of the strong support from our community and interest from our vendor partners, making it easy for teams of people like Linux and database admins to work together and get systems up quickly and ready for production.
If you’ve never used Ansible before, head to our Getting Started page or check out one of our free workshops. It’s easy to get started and learn how to start automating.
To make it easy for people to automate, we also host Ansible Galaxy, which provides easy access to roles—a more complex way to organize and structure your Ansible playbooks.
This playbook uses some common Ansible modules for configuring the base operating system, and then community modules for interacting with the MsSQL deployment after initialization.
How to install SQL Server 2017 on RHEL with Ansible
Today we’ll be looking at a role that I’ve created to install Microsoft SQL server on top of Red Hat Enterprise Linux 7, with the option of loading in a DB schema. To use this you’ll need:
- A Red Hat Enterprise Linux 7 system, configured with the appropriate repositories for RPM packages.
NOTE: I’ll be using a system from a Red Hat Certified Cloud Service Provider with preconfigured repos. If you’d like to run this locally or inside a private datacenter, you can sign up for a free Developer Subscription
- Ansible installed on your primary working system.
- The ability to SSH from your working system to your RHEL 7 system.
You’ll also want some basic familiarity with using Ansible playbooks and roles, so if you didn’t check out our Getting Started page or attend a workshop, do that first before continuing!
You can easily install my role by running the following from your Ansible system:
ansible-galaxy install kyleabenson.mssql
Or take a look at the full content online at https://github.com/kyleabenson/ansible-role-mssql
Once the role is installed, we can take a look at what these playbooks will do. Let’s first take a look at tasks/main.yml:
The really great thing about Ansible is that it’s written in YAML, so it’s really easy to see what each task is doing. There’s even flexibility for variable insertion, conditionals, and a few other tricks to make it easy to handle different environments.
We can see that this is the main playbook for installation. It handles the messy bits of configuration for us, including:
- Adding Microsoft specific repositories.
- Installing the necessary prerequisite packages.
- Running the MsSQL script.
- Enabling firewall settings when necessary.
- Making sure the services start persistently.
Let’s put together a simple playbook for calling our newly installed role:
After we’re performed the initial installation, we can create a new database pretty easily. I’m pulling a task from the roles ‘new_db.yml’ into this playbook for simplicity’s sake.
Let’s take a look at the following video which shows:
- Creating the playbook to call our Ansible role.
- Installing Microsoft SQL Server 2017.
- Creating a new database.
And just like that, we have a fully configured and ready MsSQL database. I’ve also created some playbooks in that role that make it easy to import an existing db schema, delete a db, and uninstall.
Ansible makes it incredibly easy to start automating some of our most time consuming tasks. Ansible also makes it easy to configure packages and services on Windows systems, and Azure as well.
If you’d like to see more about using Ansible to manage Windows, be sure to check out all of our Windows integrations.
That’s it for now. If you have feedback feel free to drop me a line on twitter @kyleabenson or file an issue on the GitHub Repo. Happy automating!
This post was sponsored by Command Line Heroes, an original podcast from Red Hat.