Ansible idempotent MySQL installation Playbook

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

    This is an alternative solution to the one proposed by @LorinHochStein

    One of my constraints was to ensure that no passwords are stored in plain text files anywhere on the server. Thus .my.cnf was not a practical proposition

    Solution :

    - name: update mysql root password for all root accounts from local servers
      mysql_user: login_user=root 
                  login_password={{ current_password }} 
                  name=root 
                  host=$item 
                  password={{ new_password }} 
                  priv=*.*:ALL,GRANT
      with_items:
          - $ansible_hostname
          - 127.0.0.1
          - ::1
          - localhost
    

    And in the vars file

    current_password: foobar
    new_password: "{{ current_password }}"
    

    When not changing the mysql password run ansible playbook on command line as usual.

    When changing the mysql password, add the following to the command line. Specifying it on the commandline allows the parameter set on the command line to take precedence over the one defaulted to in the vars file.

    $ ansible-playbook ........ --extra-vars "new_password=buzzz"
    

    After running the command change the vars file as follows

    current_password=buzzz
    new_password={{ current_password }}
    

提交回复
热议问题