首页 > 其他 > 详细

变量定义 - 判断文件是否存在

时间:2020-10-25 17:39:06      阅读:42      评论:0      收藏:0      [点我收藏+]

1.访问变量文件

---
- hosts: frame
  remote_user: root
  gather_facts: no
  vars_files:
  - /testdir/ansible/testfile.txt
  tasks:
  - debug:
      msg: "{{key_1}}"

变量文件:

[root@frontend-1 mytestvar]# cat /testdir/ansible/testfile.txt
key_1: values_1

2.判断文件是否存在

---
- hosts: frame
  tasks:
  - name: check wheather  file exist
    shell: ls   /etc/hosts
    register: ls_result
  - name: when last step succeed , echo ok into file /tmp/1025/hosts
    shell: echo ok  > /tmp/1025/hosts
    when: ls_result.rc == 0

 

变量定义 - 判断文件是否存在

原文:https://www.cnblogs.com/hixiaowei/p/13873110.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!