使用ansible 2.0.2.0,我想将文件部署到目标服务器。Debian 和 RedHat 系列上的目标文件夹不同。
我已经使用了set_fact,但似乎它使用了最后定义的,忽略了when:选项。
我不想使用变量文件,因为这个变量仅在这个特定的剧本中使用
将复制任务复制到 RedHat 和 Debian 中虽然可能,但会使将来的维护变得复杂。
下面的 playbook 在 Ubuntu 服务器上执行时将会失败,因为目标已扩展为 /etc/nrpe.d(适用于 RedHat)
- set_fact:
destination: "/etc/nagios/nrpe.d/"
when: ansible_os_family == "Debian"
- set_fact:
destination: "/etc/nrpe.d/"
when: ansible_os_family == "RedHat"
- name: Ensure Nagios custom checks directory exists
file: path=/usr/local/lib/nagios/plugins state=directory mode=0755
- name: Install check_cpu_steal
copy: src=eprepo/sysadmin/nagios_checks/check_cpu_steal dest=/usr/local/lib/nagios/plugins/check_cpu_steal mode=0755 owner=root group=root
- name: Install check_cpu_steal command to /etc/nrpe.d
copy: src=eprepo/sysadmin/files/check_cpu_steal.conf dest="{{ destination }}/check_cpu_steal.conf mode=0644 owner=root group=root"
Run Code Online (Sandbox Code Playgroud) 我知道要检查Galera集群状态,登录mysql客户端后应该使用的命令是:
SHOW STATUS LIKE 'wsrep%';
Run Code Online (Sandbox Code Playgroud)
但是,如何直接从命令行获取输出?
以下命令会导致错误:
[root@mariadb01 ~]# mysql -u root -p "SHOW STATUS LIKE 'wsrep%';"
Enter password:
ERROR 1049 (42000): Unknown database 'SHOW STATUS LIKE 'wsrep%';'
Run Code Online (Sandbox Code Playgroud)
我计划使用 cron 和 bash 创建一个简单的监控,因此需要使用命令行获取输出