흐름제어 구성
ansible.cfg
[student@workstation dev-flowcontrol]$ cat ansible.cfg [defaults] inventory = inventory remote_user = devops [privilege_escalation] become = true
inventory
[student@workstation dev-flowcontrol]$ cat inventory [databases] servera.lab.example.com
configure_datatbases.yml
[student@workstation dev-flowcontrol]$ cat configure_database.yml --- - yum: name: "{{ extra_packages }}" - get_url: url: "http://materials.example.com/task_control/my.cnf" dest: "{{ configure_database_path }}" owner: mysql group: mysql mode: 0644 seuser: system_u setype: mysqld_etc_t force: yes - service: name: "{{ db_service }}" state: started enabled: true
playbook.yml
[student@workstation dev-flowcontrol]$ cat playbook.yml --- - hosts: all vars: db_package: mariadb-server db_service: mariadb db_users: - db_admin - db_user configure_database_path: /etc/my.cnf tasks: - name: Create the MariaDB users user: name: "{{ item }}" with_items: "{{ db_users }}" when: inventory_hostname in groups['databases'] - name: Install the database server yum: name: "{{ db_package }}" when: db_package is defined - name: Install the database server include: configure_database.yml vars: extra_packages: - mariadb-bench - mariadb-libs - mariadb-test when: configure_database_path is defined
0 Comments