我有一个用例,我必须使用liquibase运行ansible迁移,但不知道如何实现远程连接。一个想法是创建ssh隧道,但我不确定。
用例:(在远程服务器上)
远程服务器只能通过ssh访问,而且清算库不支持ssh隧道(据我所知),也不支持清算库的ansible模块。
在完成以上任务之前,似乎有一种老生常谈的方法:
但我不确定这是解决这个问题的最好办法。
发布于 2015-11-04 05:56:10
使用java在服务器端安装液化基似乎是额外的开销,因此,ssh隧道似乎是一个可行的解决方案,我解决了这个问题如下:
Vars:
mysql:
ssh_user: "xyz@{{ inventory_hostname }}"
forward_port: 3306
listen_port: 3307
ssh_key: "{{ ansible_ssh_private_key_file }} "
definer: "'root'@'localhost'"
backup_dir: "/var/somebackup/location"任务:
- name: Kill any active ssh tunnel to current host
local_action: command bash -c "ps ax | grep ssh |grep -v grep | grep '{{ mysql.ssh_user }}' |head -n 1| xargs -n 1|head -n 1|xargs kill -KILL"
sudo: no
register: ssh_tunnel_end
- name: Create ssh tunnel to mysql
local_action: command bash -c "ssh -o ExitOnForwardFailure=yes -o ConnectTimeout=2 -i {{ mysql.ssh_key }} -f -N -L {{ mysql.listen_port }}:127.0.0.1:{{ mysql.forward_port }} {{ mysql.ssh_user }}"
sudo: no
register: ssh_tunnel_start
- name: Run liquibase migrations for each db
shell: liquibase --contexts='{{item.1.contexts}}' --username='{{customer.db.root_user}}' --password='{{customer.db.root_password}}' --changeLogFile='update.xml' --url='jdbc:mysql://127.0.0.1:{{mysql.listen_port}}/{{ customer.prefix }}_{{ item.1.db_suffix }}'
args:
chdir: "{{special_modules.migrations.dest}}/{{item.1.name}}"
delegate_to: 127.0.0.1
sudo: no
with_subelements:
- "{{ customer_modules }}"
- migrations
- name: Kill reverse ssh tunnel to mysql
local_action: command bash -c "ps ax | grep ssh |grep -v grep | grep '{{ mysql.ssh_user }}' |head -n 1|xargs -n 1|head -n 1|xargs kill -KILL"
sudo: no
register: ssh_tunnel_end发布于 2015-11-25 23:19:58
---
- name: Create Liquibase directory
file: name=/opt/liquibase state=directory mode=0755 owner=root group=root
- name: Install Liquibase
unarchive:
src: https://github.com/liquibase/liquibase/releases/download/liquibase-parent-{{ liquibase_version }}/liquibase-{{ liquibase_version }}-bin.tar.gz
dest: /opt/liquibase
copy: no
owner: root
group: root
mode: 0755
creates: /opt/liquibase/liquibasehttps://stackoverflow.com/questions/31264121
复制相似问题