Search code examples
phpsql-serverlinuxpuppet

Automate installation of msodbcsql with puppet


To install msodbcsql that comes with mssql-tools that are needed to use the PHP Microsoft SQL Driver for Linux the following command is needed

sudo ACCEPT_EULA=Y apt-get install mssql-tools

However when installing this with Puppet, this fails, the puppet code currently used

package { 'mssql-tools'      : ensure => latest, }

But this returns an error:

ERROR: The EULA was not accepted. Installation aborted.

What would be needed so Puppet can successfully install this package. I already tried setting a environment variable before calling the package command.

Exec { environment => [ "ACCEPT_EULA=Y" ] }

Microsoft's installation instructions are here:

https://blogs.msdn.microsoft.com/sqlnativeclient/2017/02/04/odbc-driver-13-1-for-linux-released/

And this is the driverpage:

https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu/


Solution

  • It appears that this is a feature that was requested; Run the package entity with an environment value.

    But since there is a feature freeze this will not be implemented in puppet 4.x (https://projects.puppetlabs.com/issues/6400)

    The workaround is to not use the package entity but the exec entity:

    exec { "/usr/bin/apt-get -yq install msodbcsql":
      environment => "ACCEPT_EULA=Y",
      unless => "/usr/bin/dpkg -l msodbcsql | tail -1 | grep ^ii",
    }
    

    Where unless is used to make it idempotent to not run if the package is already installed.

    Disadvantage of this method is that this only works when using apt-get if you would want this to work on other systems as well you should provide an $osfamily with if statement to use the correct package manager.