我想編寫一個Ansible手冊,只編譯Nginx,如果它不存在並且在當前版本中。然而它每次編譯都是不可取的。當字符串不匹配時有條件的情況
這是我有:
- shell: /usr/local/nginx/sbin/nginx -v 2>&1
register: nginxVersion
- debug:
var=nginxVersion
- name: install nginx
shell: /var/local/ansible/nginx/makenginx.sh
when: "not nginxVersion == 'nginx version: nginx/1.8.0'"
become: yes
腳本都從它的每一個編譯Nginx的時候運行shell腳本的事實行爲以外。 nginxVersion的調試輸出是:
ok: [server] => {
"var": {
"nginxVersion": {
"changed": true,
"cmd": "/usr/local/nginx/sbin/nginx -v 2>&1",
"delta": "0:00:00.003752",
"end": "2015-09-25 16:45:26.500409",
"invocation": {
"module_args": "/usr/local/nginx/sbin/nginx -v 2>&1",
"module_name": "shell"
},
"rc": 0,
"start": "2015-09-25 16:45:26.496657",
"stderr": "",
"stdout": "nginx version: nginx/1.8.0",
"stdout_lines": [
"nginx version: nginx/1.8.0"
],
"warnings": []
}
}
}
根據文檔,我在正確的線上,我錯過了什麼簡單的技巧?
嗯,這實在是太容易了。第二個選項奏效。 –