Ansible idempotent MySQL installation Playbook

后端 未结 11 1383
后悔当初
后悔当初 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:56

    Adding to the previous answers, I didn't want a manual step before running the command, ie I want to spin up a new server and just run the playbook without having to manually change the root password first time. I don't believe {{ mysql_password }} will work the first time, when root password is null, because mysql_password still has to be defined somewhere (unless you want to override it with -e).

    So I added a rule to do that, which is ignored if it fails. This is in addition to, and appears before, any of the other commands here.

    - name: Change root user password on first run
      mysql_user: login_user=root
                  login_password=''
                  name=root
                  password={{ mysql_root_password }}
                  priv=*.*:ALL,GRANT
                  host={{ item }}
          with_items:
            - $ansible_hostname
            - 127.0.0.1
            - ::1
            - localhost
          ignore_errors: true
    

提交回复
热议问题