- 说明:该 playbook 使用了变更的定义与引用,在 tasks 任务完成后触发了 handlers 任务程序。
- 实现:MariaDB 的安装与配置文件的更新,服务的启动与 MariaDB 的 root 账号密码初始化等工作。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
--- - name: Install Mariadb server hosts: databases vars: db_packages: - mariadb-server - MySQL-python db_service: mariadb src_file: "http://materials.example.com/task_control/my.cnf.template" dst_file: /etc/my.cnf tasks: - name: Install {{ db_packages }} package yum: name: "{{ item }}" state: latest with_items: "{{ db_packages }}" notify: - start_service - name: Download and install {{ dst_file }} get_url: url: "{{ src_file }}" dest: "{{ dst_file }}" owner: mysql group: mysql force: yes notify: - restart_service - set_password handlers: - name: start_service service: name: "{{ db_service }}" state: started - name: restart_service service: name: "{{ db_service }}" state: restarted - name: set_password mysql_user: name: root password: redhat ... |