作者:朱泊潇 | 来源:互联网 | 2023-02-10 13:06
在一个ansible playbook中,如果需要升级,我想停止MariaDB(从我的情况下,从RPM包中重新启动并不总是有效).我对ansible很新.
我想出了这个:
- name: "Check if MariaDB needs to be upgraded"
shell: "yum check-update MariaDB-server|grep MariaDB|wc -l"
register: needs_update
- name: "Stop mysql service"
service:
name: mysql
state: stopped
when: needs_update.stdout == "1"
有没有更好的方法来执行此操作然后执行shell命令?运行时,我收到警告:
TASK [mariadb_galera : Check if MariaDB needs to be upgraded] ******************
changed: [139.162.220.42] => {"changed": true, "cmd": "yum check-update MariaDB-server|grep MariaDB|wc -l", "delta": "0:00:00.540862", "end": "2017-03-01 13:03:34.415272", "rc": 0, "start": "2017-03-01 13:03:33.874410", "stderr": "", "stdout": "0", "stdout_lines": ["0"], "warnings": ["Consider using yum module rather than running yum"]}
[WARNING]: Consider using yum module rather than running yum
谢谢!
1> Konstantin S..:
您可以隐藏警告:
- name: "Check if MariaDB needs to be upgraded"
shell: "yum check-update MariaDB-server|grep MariaDB|wc -l"
args:
warn: false
register: needs_update
或者你可以欺骗Ansible执行yum
任务check_mode
:
- name: "Check if MariaDB needs to be upgraded (CHECK MODE!)"
yum:
name: MariaDB-server
state: latest
check_mode: yes
register: needs_update_check
- name: "Stop mysql service"
service:
name: mysql
state: stopped
when: needs_update_check | changed
请在使用前测试此代码.