Import sql script to rds database

21 views
Skip to first unread message

Biraj Sahu

unread,
Nov 20, 2019, 9:06:24 AM11/20/19
to Ansible Development
Hello Friends,
I am in need of some help in ansible.

I am pretty new to ansible and I want to achieve the following as part of my work:

- As part of regular deployment of our application, we would have a sql script(which would alert tables, add tables etc) which needs to be run on say 3 schema in a region and 5 schema in another. The application is in aws and the database is arora db(RDS). My problem is I am not sure how do I parametrize  to make it run on each schema, first one after the other and then can upgrade that to run in parallel.

I did the following in a playbook:
- hosts: localhost
 
  vars:
    script_file: "{{ path }}"
  tasks:
  - name: rds_manage_user - run .sql script to alert and create new tables
    shell: "mysql -h {{ item.host }} -u {{ item.user }} -p{{ item.password }} < {{ script_file }} >> /usr/local/testscript.log"
    with_items:
        - { host: testhost1.com, user: testuser1, password: "testpass1" }
        - { host: testhost2.com, user: testuser2, password: "testpass2" }

This works and I get the desired output. But how do I pass these hostname, user and password from an external file and it can run through the file and get the script executed in all schemas.

Any help/suggestions would be greatly appreciated. Thanks in advance
Reply all
Reply to author
Forward
0 new messages