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