ansible - 当条件下跳过剧本任务
问题描述
我是 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
如何使任务运行?
解决方案
推荐阅读
- powershell - 如何使用powershell将参数从另一个管道输出传递给函数
- java - 自定义 java gradle 插件中的反射
- function - 如何从 cmake 函数中设置“全局”cmake 变量
- c - 共享锁字中的离散锁与锁位
- matlab - matlab错误particleswarm目标函数必须返回标量值
- c# - 对象C#的转义字符串构建
- jquery - 我正在构建的 Wordpress 页面正在使我的 iPhone 崩溃
- python - 具有定义边缘的 Python 3 OpenCV 颜色对象检测
- python - 如何在 Python 中将日期时间文本转换为日期时间对象?
- git - 用于将特定文本(模式)移动到不同列的 Shell 命令