0
我試圖用Ansible
來檢查SELinux
是否啓用(設置爲強制),如果沒有,啓用它。只有在SELinux
被禁用時,才能調用play
以啓用SELinux
。根據另一個播放的輸出調用另一個「播放」 - Ansible
的playbook
看起來像這樣:
- hosts: all
# root should execute this.
remote_user: root
become: yes
tasks:
# Check if SELinux is enabled.
- name: check if selinux is enabled
tags: selinuxCheck
register: selinuxCheckOut
command: getenforce
- debug: var=selinuxCheckOut.stdout_lines
- name: enable selinux if not enabled already
tags: enableSELinux
selinux: policy=targeted state=enforcing
when: selinuxCheckOut.stdout_lines == "Enforcing"
- debug: var=enableSELinuxOut.stdout_lines
當我運行此,任務enableSELinux
失敗的原因,「條件檢查失敗」。輸出是:
TASK [debug] *******************************************************************
task path: /root/ansible/playbooks/selinuxConfig.yml:24
ok: [localhost] => {
"selinuxCheckOut.stdout_lines": [
"Enforcing"
]
}
TASK [enable selinux if not enabled already] ***********************************
task path: /root/ansible/playbooks/selinuxConfig.yml:26
skipping: [localhost] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}
我的問題:
1.這是得到發揮依賴於從另一齣戲的輸出執行正確的方法是什麼?
2.我如何得到這個工作?