{"id":19230382,"url":"https://github.com/elmarx/ansible-mysql-query","last_synced_at":"2025-04-21T03:30:55.855Z","repository":{"id":27687977,"uuid":"31174463","full_name":"elmarx/ansible-mysql-query","owner":"elmarx","description":"Ansible custom module that allows you to set values in mysql databases","archived":false,"fork":false,"pushed_at":"2022-03-29T22:00:22.000Z","size":158,"stargazers_count":33,"open_issues_count":14,"forks_count":27,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-21T00:59:00.381Z","etag":null,"topics":["ansible","mysql"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elmarx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-22T18:44:01.000Z","updated_at":"2023-08-14T09:51:44.000Z","dependencies_parsed_at":"2022-09-08T01:11:53.962Z","dependency_job_id":null,"html_url":"https://github.com/elmarx/ansible-mysql-query","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmarx%2Fansible-mysql-query","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmarx%2Fansible-mysql-query/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmarx%2Fansible-mysql-query/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmarx%2Fansible-mysql-query/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elmarx","download_url":"https://codeload.github.com/elmarx/ansible-mysql-query/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223848306,"owners_count":17213598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","mysql"],"created_at":"2024-11-09T15:37:58.106Z","updated_at":"2024-11-09T15:37:58.672Z","avatar_url":"https://github.com/elmarx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Ansible Role: mysql_query\n===================\n\nAnsible module to set values in a mysql table, or insert records. Useful for web-applications that store configurations in database. E.g. icingaweb2 requires the initial user to be inserted into the database. The install-wizard could do it, but with ansible you want to automate installation ;)\n\nListed at Ansible Galaxy Page as [zauberpony.mysql-query](https://galaxy.ansible.com/zauberpony/mysql-query/).\n\nInstall\n-------\n\nInstall via ansible-galaxy, `ansible-galaxy install zauberpony.mysql-query`, or manually put the file *mysql_query* into your *roles_path*.\n\n### Requirements:\n\npython bindings for mysql (just like the core mysql_* modules):\n\n- MySQLdb (Python 2.x only)\n- PyMySQL (Python 2.7 and python 3.x)\n\n\nExample playbook\n----------------\n\n### A complete example that ensures a record is present in a given table.\n\n```yaml\n\n---\n- hosts: all\n  roles:\n    - zauberpony.mysql-query\n  tasks:\n    - name: insert a row\n      mysql_query:\n        name: ansible-playbook-example\n        table: simple_table\n        login_host: ::1\n        login_user: root\n        login_password: password\n        identifiers:\n          id: 14\n          email: 'john@example.com'\n        values:\n          role: \"admin\"\n          department: 'IT'\n        defaults:\n          password: \"secret\"\n          last_login: 1469264933\n```\n\nGiven a table `simple_table` with columns (*id*, *email*, *role*, *department*, *password*, *last_login*), this example would:\n- Look for a row *where id = 14 and email = 'john@example.com'*\n  - if the row does not exist: insert a row with id=14, email='john@example.com', role=\"admin\", department=\"IT\", password=\"secret\", last_login=1469264933\n  - if the row does exist: check if the ***values*** (role, department) match the given values, if not: update\n\nThus:\n- *identifiers* are being used to check for existence and to find a row\n- *defaults* are being used as default values if the row is not present (i.e.: only used for insert)\n- *values* are the state of the row that ansible ensures\n\n### A complete example that ensures a record is not present in a given table.\n\n```yaml\n\n---\n- hosts: all\n  roles:\n    - zauberpony.mysql-query\n  tasks:\n    - name: insert a row\n      mysql_query:\n        state: absent\n        name: ansible-playbook-example\n        table: simple_table\n        login_host: ::1\n        login_user: root\n        login_password: password\n        identifiers:\n          id: 14\n          email: 'john@example.com'\n```\n\n### Running the examples from sources\n\nMake sure you have a running mysql server (e.g.: use the *docker-compose.yml*-file) and update the connection-parameters if necessary.\n\nRun via `ansible-playbook -i demo.yml` (or even simpler `./demo.yml`) and undo (to start all over) with `ansible-playbook -i reset.yml`.\n\nAfter running `./demo.yml`, you can run `./checkmode-demo.yml -C` to test ansible's [check mode](https://docs.ansible.com/ansible/latest/user_guide/playbooks_checkmode.html).\nJust run `./demo.yml` and `./checkmode-demo.yml` a few times with `-C` and without `-C` to get a feel for it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmarx%2Fansible-mysql-query","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felmarx%2Fansible-mysql-query","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmarx%2Fansible-mysql-query/lists"}