How to create a large database with Ansible

Suppose you have a sql database.sql file that creates a database schema, a table inside it, and some initial fill. Usually I can use the opportunity to create this database:

---

- name: copy database.sql to server
  template: src=database.sql dest=/tmp/database.sql owner=root group=root

- name: sql the thing into MySQL
  command: mysql "-u root -p{{ mysql_root_password }} < /tmp/database.sql"

- name: remove the sql file from the server
  command: rm -f /tmp/database.sql

and that does exactly what he says. But when database.sql is big (maybe 2 TByte), you really don't want the copy action to be the first. Are there any ways to refer to database.sql as a file on the host server (where we push it from), so you can do mysql -u root @master -p ... <"local file", so the copy action is larger not required?

+3
source share
1 answer

, , , . , copy template: Jinja, .

local_action mysql:

- name: feed database.sql to server
  local_action: shell mysql -u root -p{{ mysql_root_password }} -h {{ ansible_default_ipv4 }} < /tmp/database.sql

, :

  • DB /tmp/database.sql localmachine
  • /tmp/database.sql
  • mysql (: + bind_address)

, mysql_db:

- name: feed database.sql to server
  local_action: mysql_db login_user=root login_password={{ mysql_root_password }} login_host={{ ansible_default_ipv4 }} name={{ db_name }} state=import target=/tmp/database.sql
+8

All Articles