Type string error with mariadb master slave replication setup using mysql_replication module.

Hi,

I am trying to setup master-slave replication on mariadb 10.2. I am running ansible version 2.3.1.0. When running the playbook, I received errors about argument of type string. This is very odd because from the output of debug, the log position is obviously of type integer. I have tried to convert it (using | int) without any luck. Would anyone be able to shed some light and if there’s any work around to the problem? Thanks for all your help.

TASK [corexdb : Display output of “SHOW MASTER STATUS”] ************************

skipping: [pdus-servdb1.us.roamvu.net]

ok: [pdmaster.us.roamvu.net] => {

“master_status”: {

“Binlog_Do_DB”: “pdmaster”,

“Binlog_Ignore_DB”: “”,

“File”: “mysql-bin.000007”,

“Is_Master”: true,

“Position”: 342,

“changed”: false

}

}

failed: [pdus-servdb1.us.roamvu.net] (item={u’password’: u’slaveservice’, u’name’: u’slaveservice’}) => {“failed”: true, “item”: {“name”: “slaveservice”, “password”: “slaveservice”}, “msg”: “argument master_log_pos is of type <type ‘str’> and we were unable to convert to int: invalid literal for int() with base 10: ‘master_status.Position | int’”}

  • name: Check master replication status.

mysql_replication: mode=getmaster

delegate_to: “{{ db_master }}”

register: master_status

when: db_repl_type == “master”

  • name: Display output of “SHOW MASTER STATUS”

debug: var=master_status

when: db_repl_type == “master”

  • name: Configure replication on the slave.

mysql_replication:

mode: changemaster

master_host: “{{ db_master }}”

master_user: “{{ item.name }}”

master_password: “{{ item.password }}”

master_log_file: master_status.File

master_log_pos: master_status.Position | int

with_items:

“{{ db_repl_user }}”

when: db_repl_type == “slave”

Hi, at minimum you’ll need double curly braces around the variables to make them expand like this:

  • name: Configure replication on the slave.

mysql_replication:

mode: changemaster

master_host: “{{ db_master }}”

master_user: “{{ item.name }}”

master_password: “{{ item.password }}”

master_log_file: “{{ master_status.File }}”

master_log_pos: “{{ master_status.Position | int }}”

with_items:

“{{ db_repl_user }}”

I added the braces around master_log_file’s argument and master_log_pos’s argument.

-Toshio

Hi Toshio,

I found my mistake in the check master replication status which should be:

when: db_repl_type == “slave”

And you are right, the double curly braces are needed.

Thanks for your help.

Alex