12

I am using Ansible to provision MS SQL Server 2017 to a CentOS 7.4 box. I first went through this guide via command line and it works, but my end goal is to "Ansible-ize" it. However, when I get to the step about installing the command line tools, the -y switch does not work for accepting the license.

[user@host ~]$ sudo yum install -y mssql-tools unixODBC-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mssql-tools.x86_64 0:14.0.6.0-1 will be installed
--> Processing Dependency: msodbcsql < 13.2.0.0 for package: mssql-tools-14.0.6.0-1.x86_64
--> Processing Dependency: msodbcsql >= 13.1.0.0 for package: mssql-tools-14.0.6.0-1.x86_64
---> Package unixODBC-devel.x86_64 0:2.3.1-11.el7 will be installed
--> Running transaction check
---> Package msodbcsql.x86_64 0:13.1.9.1-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package          Arch     Version          Repository                     Size
================================================================================
Installing:
 mssql-tools      x86_64   14.0.6.0-1       packages-microsoft-com-prod   249 k
 unixODBC-devel   x86_64   2.3.1-11.el7     pwbank_repo                    55 k
Installing for dependencies:
 msodbcsql        x86_64   13.1.9.1-1       packages-microsoft-com-prod   4.0 M

Transaction Summary
================================================================================
Install  2 Packages (+1 Dependent package)

Total size: 4.2 M
Installed size: 4.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
The license terms for this product can be downloaded from
https://aka.ms/odbc131eula and found in
/usr/share/doc/msodbcsql/LICENSE.TXT . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
YES
  Installing : msodbcsql-13.1.9.1-1.x86_64                                  1/3 
The license terms for this product can be downloaded from
http://go.microsoft.com/fwlink/?LinkId=746949 and found in
/usr/share/doc/mssql-tools/LICENSE.txt . By entering 'YES',
you indicate that you accept the license terms.

Do you accept the license terms? (Enter YES or NO)
YES
  Installing : mssql-tools-14.0.6.0-1.x86_64                                2/3 
  Installing : unixODBC-devel-2.3.1-11.el7.x86_64                           3/3 
  Verifying  : msodbcsql-13.1.9.1-1.x86_64                                  1/3 
  Verifying  : unixODBC-devel-2.3.1-11.el7.x86_64                           2/3 
  Verifying  : mssql-tools-14.0.6.0-1.x86_64                                3/3 

Installed:
  mssql-tools.x86_64 0:14.0.6.0-1      unixODBC-devel.x86_64 0:2.3.1-11.el7     

Dependency Installed:
  msodbcsql.x86_64 0:13.1.9.1-1                                                 

Complete!

I noticed that there is a warning before I am prompted saying RPMDB altered outside of yum. Does this mean that Microsoft has specifically modified this rpm in their own way and, because of this, yum doesn't know how to handle it?

My Goal

Although the above works for a "by hand" install, I am trying to "ansible-ize" the above. My playbook works up until I get to this play:

- name: Upgrade all installed packages, and install new ones
  package:
    name: '{{item}}'
    state: latest
  with_items:
    - '*'
    - mssql-server
    - mssql-tools
    - unixODBC-devel

The above play will update all of my currently installed packages and install MS SQL Server 2017 just fine, but it will hang while trying to install the mssql-tools package, I assume because it is waiting for the user to accept the license.

My Question

How can I "ansible-ize" this install if my playbook hangs, waiting for the user to accept the license?

For bonus points, there's a step where I have to run sudo /opt/mssql/bin/mssql-conf setup and follow the on screen prompts which, again, impedes my provisioning. I am in the process of going through it once, finding its output file and seeing if I can't just copy that in whenever I re-provision a new box. Alternatively, I am in the process of reading up on Expect.

1
  • Some old versions of MSODBC had a command line switch: ./install.sh install --accept-license Commented May 23, 2021 at 18:43

3 Answers 3

14
- name: install mssql-server repo (CentOS, RedHat)
  get_url:
    url: "{{ centos_repo_url }}"
    dest: /etc/yum.repos.d/mssql-server.repo
  when: ansible_distribution in ['CentOS', 'RedHat']

- name: install mssql-server repo (Ubuntu)
  get_url:
    url: "{{ ubuntu_repo_url }}"
    dest: /etc/apt/sources.list.d/mssql-server.list
  when: ansible_distribution == 'Ubuntu'

- name: refresh apt-get cache for server repo (Ubuntu)
  command: apt-get update
  when: ansible_distribution == 'Ubuntu'

- name: install mssql-server package
  package:
    name: mssql-server
    state: latest

- name: install mssql-tools package
  package:
    name: mssql-tools
    state: latest
  environment:
    ACCEPT_EULA: 'y'

A sample playbook for installing and configuring SQL Server (along with creating a Pacemaker-managed Availability Group) is available at https://github.com/Microsoft/sql-server-samples/tree/master/samples/features/high%20availability/Linux/Ansible%20Playbook

2
  • 2
    Thank you, this fixed it. It was specifically the environment: ACCEPT_EULA: 'y' that I was missing. Commented Oct 3, 2017 at 19:55
  • FYI, a sample playbook for installing and configuring SQL Server is now available at github.com/Microsoft/sql-server-samples/tree/master/samples/… Commented Oct 17, 2017 at 18:29
11

This should work in terms of EULA for Tools

sudo ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev

As far as unattended install, you can specify environment variables or command line options for most things during setup. Take a look at Sample: Unattended SQL Server installation script for Red Hat Enterprise Linux.

NOTE: I noticed the repo in the links is still pointing to the older pre-RTM repo. Please use these repos while we correct them.

2
  • 1
    I'm not using apt-get, I'm using yum. I'll try this in a bit here and let you know what I find. Thank you! Commented Oct 3, 2017 at 14:32
  • I just checked this way with yum and it works perfectly fine. Thanks! Commented Oct 1, 2019 at 6:47
0

If you are using rpm -ivh and want to run the setup non-interactively. Follow the steps mentioned.

Tested on Ubuntu and redat/ubi8-init

  • export ACCEPT_EULA='y'
  • rpm -ivh <package_name>

If you are trying to achieve the same in Dockerfile use the following:

RUN export ACCEPT_EULA='y' && rpm -ivh msodbcsql****.rpm

Note: Make sure export and rpm command is issues against a single RUN.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.