Quantcast
Channel: Blog Virtualizacion
Viewing all articles
Browse latest Browse all 679

Ansible: Instalar SQL Server 2019 en Linux

$
0
0

Ansible: Instalar SQL Server 2019 en Linux

En la entrada anterior, hemos visto cómo instalar y configurar SQL Server 2019 sobre un Centos 8 / RedHat 8.

En la siguiente entrada, vamos a intentar automatizar el proceso mediante Ansible. Así que vamos a llevar todos los pasos de la entrada anterior a un fichero automatizado.

Copiamos la clave de la máquina remota:

[root@TERRAFORM mssql2019-roles-RHEL8]# ssh-copy-id -i /root/.ssh/id_rsa 192.168.2.175
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.2.175 (192.168.2.175)' can't be established.
ECDSA key fingerprint is SHA256:VD8qsa1L++EIbxWi+bntigE+Zht23u6h2/MuklE4MA4.
ECDSA key fingerprint is MD5:f5:81:c1:e7:67:88:12:26:ce:94:c5:cf:aa:45:c3:1d.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.2.175's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.2.175'"
and check to make sure that only the key(s) you wanted were added.

Generamos el fichero de inventario:

[root@TERRAFORM mssql2019-roles-RHEL8]# cat ../inventory/sql 
[sql]
SQLSERVER02 ansible_ssh_host=192.168.2.175

Lo primero que haremos para instalar el software, es copiar el repo de Ansible para SQL Server en nuestro server:

git clone https://github.com/mikecali/mssql2019-roles-RHEL8

[root@TERRAFORM ansible]# git clone https://github.com/mikecali/mssql2019-roles-RHEL8
Cloning into 'mssql2019-roles-RHEL8'...
remote: Enumerating objects: 74, done.
remote: Counting objects: 100% (74/74), done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 74 (delta 22), reused 48 (delta 7), pack-reused 0
Unpacking objects: 100% (74/74), done.

Nos movemos al directorio:

[root@TERRAFORM ansible]# cd mssql2019-roles-RHEL8
[root@TERRAFORM mssql2019-roles-RHEL8]# ls
README.md  ansible.cfg  roles  site-del.yaml  site.yaml  vars.yaml

Editamos los ficheros site.yaml y vars.yaml con nuestras configuraciones si no lo queremos en el propio servidor, que sino serán validados, con los cambios pertinentes:

[root@TERRAFORM mssql2019-roles-RHEL8]# cat site.yaml 
---
- hosts: localhost
  become: yes
  roles:
    - pre-reqs
    - ansible-role-mssql
  tasks:
    - name: Wait up to 60 seconds for server to become available after creation
      wait_for:
        port: 1433
        timeout: 60
    - name: Create new db
      include_role:
        name: ansible-role-mssql
        tasks_from: new_db
[root@TERRAFORM mssql2019-roles-RHEL8]# cat vars.yaml
# These are required for database installation
#
end_user_license_aggreement_consent_server: Y # Must be Y or N
end_user_license_aggreement_consent_cli: "YES" # Must be YES or NO in all caps within quotes
edition: evaluation

# For use when creating, importing, or deleting databases
db_name: pub
db_host: 127.0.0.1
db_port: 1433
db_user: sa
db_password: P@ssWORD!

Os dejo las mías:

---
- hosts: sql
  become: yes
  roles:
    - pre-reqs
    - ansible-role-mssql
  tasks:
    - name: Wait up to 60 seconds for server to become available after creation
      wait_for:
        port: 1433
        timeout: 60
    - name: Create elblogdenegu db
      include_role:
        name: ansible-role-mssql
        tasks_from: elblogdenegu_db

# These are required for database installation
#
end_user_license_aggreement_consent_server: Y # Must be Y or N
end_user_license_aggreement_consent_cli: "YES" # Must be YES or NO in all caps within quotes
edition: developer

# For use when creating, importing, or deleting databases
db_name: elblogdeneguDB
db_host: 127.0.0.1
db_port: 1433
db_user: sa
db_password: P@ssWORD!

Ejecutamos la instalación (en un LXC de Proxmox tengo que instalar SUDO antes de ejecutar, sino da errores). Se generará un gran “churro”:

ansible-playbook -i ../inventory/sql site.yaml -e @vars.yaml -vvv

[root@TERRAFORM mssql2019-roles-RHEL8]# ansible-playbook -i ../inventory/sql site.yaml -e @vars.yaml -vvv
ansible-playbook 2.9.10
  config file = /etc/ansible/mssql2019-roles-RHEL8/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible-playbook
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/mssql2019-roles-RHEL8/ansible.cfg as config file
host_list declined parsing /etc/ansible/inventory/sql as it did not pass its verify_file() method
script declined parsing /etc/ansible/inventory/sql as it did not pass its verify_file() method
auto declined parsing /etc/ansible/inventory/sql as it did not pass its verify_file() method
Parsed /etc/ansible/inventory/sql inventory source with ini plugin

PLAYBOOK: site.yaml *******************************************************************************************************************************************
1 plays in site.yaml

PLAY [sql] ****************************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************************
task path: /etc/ansible/mssql2019-roles-RHEL8/site.yaml:2
<192.168.2.175> ESTABLISH SSH CONNECTION FOR USER: None
...

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=18   changed=15    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

Espero os parezca interesante…

¿Te ha gustado la entrada SÍGUENOS EN TWITTER?

La entrada Ansible: Instalar SQL Server 2019 en Linux se publicó primero en Blog Virtualizacion.


Viewing all articles
Browse latest Browse all 679