首页 > 解决方案 > 当条件下跳过剧本任务

问题描述

我是 Ansible 的新手。

以下是以安全方式在独立机器上安装 MySQL 的任务。当条件不满足并且在默认值中定义时,这些任务将被跳过。条件在默认目录中定义。

主要的.yml

---

# mysql data directory
mysql_data_dir: /data/mysql

mysql_backup_dir: /data/mysql_backup

# Set this to `yes` to forcibly update the root password.
mysql_root_password_update: yes

# Set this to true to secure the mysql install
mysql_secure_installation: true

mysql_root_username: root

# admin user to create
mysql_admin_user_username: admin

# Set to % to allow logins from any host (useful for director)
mysql_admin_user_host: '%'

mysql_log_dir: /data/mysql/log
# Set this to `yes` to forcibly update the root password.
mysql_root_password_update: yes

# Set this to true to secure the mysql install
mysql_secure_installation: true

mysql_root_username: root
mysql_root_home: /root

# Replication variables
deploy_mysql_replication: False
mysql_replication_user:
  name: repl
  host: '%'

mysql_admin:
   user: admin
   host: '%'    

- name: Install MySQL Server
  yum:
    name: MariaDB-server
    state: present

- name: Install MySQLdb Python package for secure installations.
  yum:
    name: MySQL-python
    state: present
  when: mysql_secure_installation and mysql_root_password is defined

- name: MySQL | Create Master MySQL configuration file
  template:
    src: master.my.cnf.j2
    dest: /etc/my.cnf
    backup: yes
    owner: root
    group: root
    mode: 0644
  when: inventory_hostname == mysql_replication_master

如何使任务运行?

标签: ansibleconditional-statements

解决方案


推荐阅读