geerlingguy / ansible-role-mysql

Ansible Role - MySQL
https://galaxy.ansible.com/geerlingguy/mysql/
MIT License
1.05k stars 861 forks source link

Allow replica master to be differ from local inventory + fix Is_Replica or Is_Slave #503

Closed giorgioma closed 1 year ago

giorgioma commented 1 year ago

E.g. I am running ansible on my local machine and they are accessible over public IP but i want the master and the slave to communicate over some other network interface card.

mysql_replication_master_inventory_host defaults to mysql_replication_master so it's a non-breaking change

giorgioma commented 1 year ago

I have upgraded some dependencies in my dev environment (MariaDB) and my slave data from getreplica is now

ok: [db2] => {
    "slave": {
        "Is_Replica": false,
        "changed": false,
        "failed": false,
        "msg": "Server is not configured as mysql replica",
        "queries": []
    }
}

but the current check is (slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Slave is not defined and slave is failed) I am guessing it should now be (slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Replica is defined and not slave.Is_Replica) or (slave.Is_Slave is not defined and slave.Is_Replica is not defined and slave is failed) to cover both cases for the naming transition

giorgioma commented 1 year ago

Well that was a quick merge! Cheers

liammcdermott commented 1 year ago

Hey @giorgioma, I'm just wonder if there's a reason the task: - name: Start replication. didn't get the same treatment? It still has the old behaviour of only checking slave.Is_Slave.

I notice the logic of that when might be incorrect, is that the reason you didn't touch it?

Edit: what I mean when I say the logic of the Start replication task's when clause might be incorrect, is that it never triggers for me. I'm not 100% sure why, but I believe it's because earlier tasks set the replication up, so not slave.Is_Replica always evaluates to false. Removing the not from not slave.Is_Replica works for me.

hahayusuf commented 1 year ago

I am having the same issue of Start replication never triggering. Not sure why this is the case.

See below for logs that may help:

image

Update: when I comment out the slave.Is_Replica it works as expected. Still not sure what is wrong with the when conditions.

liammcdermott commented 1 year ago

@hahayusuf I think what's wrong with it is mentioned in my edit. not save.Is_Replica evaluates to false, since the replication is setup (even though it's not started). I tested and at least this was the case for me.

I changed the when for Start replication to this:

- (slave.Is_Slave is defined and slave.Is_Slave) or (slave.Is_Replica is defined and slave.Is_Replica) or (slave.Is_Slave is not defined and slave.Is_Replica is not defined and slave is failed)
giorgioma commented 1 year ago

Ah yes! I was informed i broke my staging env as well, i'll open a pr in the morning I simply didn't notice that the last command had that condition as well

liammcdermott commented 1 year ago

@giorgioma No worries, I created #511. Would you mind trying that out and seeing if it works for you?