发生条件时跳过Playbook任务

时间:2019-07-31 09:13:38

标签: ansible conditional-statements

我是Ansible的新手。

以下是以安全方式在独立计算机上安装MySQL的任务。如果不满足条件(默认情况下已定义),则会跳过任务。条件在默认目录中定义。

main.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

如何使任务运行?

0 个答案:

没有答案