핸들러 구현

ansible.cfg
[student@workstation dev-handlers]$ cat ansible.cfg 
[defaults]
inventory   = inventory
remote_user = devops

[privilege_escalation]
become      = true
inventory
[student@workstation dev-handlers]$ cat inventory 
[databases]
servera.lab.example.com
configure_db.yml
[student@workstation dev-handlers]$ cat configure_db.yml 
---
- name: Installing 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
  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.