我是ansible的新手,因此任何帮助都将不胜感激。
在我尝试向远程Centos服务器推送VMware工具之前,我需要检查它们是否有可写的/boot。如果它是只读的,安装将失败。如何为这个原始的Linux命令添加另一个WHEN?我知道是否必须使用register或standard out,但我找不到示例来指导我。
RAW Linux Would be >
mount | grep boot并且我需要捕获rw,目标不能像本例中那样是ro。
>
/dev/sda1 on /boot type ext4 (ro,relatime,data=ordered)我尝试在块下添加任务,就像ansible文档中那样。
- name: Catch Targets with read only boot
tasks:
- command: mount | grep boot
register: boot_mode
- shell: echo "motd contains the word hi"
when: boot_mode.stdout.find('ro') != -1
---
- name: Wrapper for conditional tasks
block:
- name: Copy Files from Mirror to Remote Guest
get_url:
url: "{{ item }}"
dest: /tmp
owner: root
group: root
with_items:
- http://mirror.compuscan.co.za/repo/vmwaretools65u2/CentOS7/VMwareTools-10.3.5-10430147.tar.gz
- name: UnTAR the installer
unarchive:
src: /tmp/VMwareTools-10.3.5-10430147.tar.gz
dest: /tmp
remote_src: yes
- name: Run the PL install
become: yes
command: /tmp/vmware-tools-distrib/vmware-install.pl -d
- name: Perform Clean Up
file:
state: absent
path: "{{ item }}"
with_items:
- /tmp/vmware-tools-distrib/
- /tmp/VMwareTools-10.3.5-10430147.tar.gz
- name: Report on success or failure
service:
name: vmware-tools
state: started
enabled: yes
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version == '7'
ignore_errors: yes我希望角色/行动手册在只读/boot模式下忽略目标。
发布于 2019-07-24 22:28:35
将stat任务放在块的前面
- stat:
path: /boot
register: boot_mode when:
- boot_mode.stat.writeable
- ansible_distribution == 'CentOS'
- ansible_distribution_major_version == '7'https://stackoverflow.com/questions/57183777
复制相似问题