Ansible idempotent MySQL installation Playbook

后端 未结 11 1676
后悔当初
后悔当初 2021-01-30 04:29

I want to setup a MySQL server on AWS, using Ansible for the configuration management. I am using the default AMI from Amazon (ami-3275ee5b), which uses yum

11条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 04:57

    The following will Work (Insert my.cnf in between 2 mysql_user calls)


    - name: 'Install MySQL'
        yum: name={{ item }} state=present
        with_items:
        - MySQL-python
        - mysql
        - mysql-server
        notify:
         - restart-mysql
    - name: 'Start Mysql Service'
      action: service name=mysqld state=started enabled=yes
    - name: 'Update Mysql Root Password'
      mysql_user: name=root host=localhost password={{ mysql_root_password }} state=present
    - name: 'Copy Conf file with root password credentials'
      template: src=../templates/my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600
    - name: 'Update Rest-Mysql Root Password'
      mysql_user: name=root host={{ item }} password={{ mysql_root_password }} state=present
        with_items:
        - "{{ ansible_hostname }}"
        - "{{ ansible_eth0.ipv4.address }}"
        - 127.0.0.1
        - ::1
    - name: 'Delete anonymous MySQL server user from server'
      mysql_user: name="" host={{ ansible_hostname }} state="absent"
    

提交回复
热议问题