如果系统已安装Oracle Linux,如何检查已安装的操作系统并继续下载文件。
这就是我要做的
- hosts: all
become: true
gather_facts: true
tasks:
- name: Check if oracle linux is installed
shell: |
cat: /etc/system-release
register: os_name
ignore_errors: yes
- debug:
msg: "{{os_name.stdout}}"```
答案 0 :(得分:0)
- hosts: all
become: yes
gather_facts: true
tasks:
- name: downloading file if Oracle Linux is there
get_url:
url: #url of the file to download
dest: #path where you want to store it eg. /etc/downloaded-file
mode: '0600' #permissions to be given to the file
when: ansible_facts['distribution'] == "OracleLinux"
您可能需要阅读本参考资料。
1. variable discover from system: Facts
2. Downloads files from HTTP, HTTPS, or FTP to node
答案 1 :(得分:0)
您应该使用ansible gather_facts: yes
输出,以便您的ansible剧本在所有平台上都是通用的,否则阅读/etc/system-release
不适用于所有平台。
Refer
- hosts: all
become: true
gather_facts: yes
tasks:
- name: Distribution
debug: msg="{{ ansible_distribution }}"
答案 2 :(得分:0)
所有其他答案都是正确的。 如果由于某些原因(例如,目标主机上的python不可用)而您不能/不想收集事实,则这是一种丑陋的方式:
- hosts: whatever
gather_facts: no
tasks:
- name: Register the system release
raw: cat /etc/system-release
register: system_release
changed_when: no
check_mode: no
- name: Do something for Oracle systems
...
when: "{{ system_release.stdout|trim is match('.*Oracle Linux.*') }}"