2016-09-27 96 views

回答

0

像这样创建一个新的任务:

- name: Put path in file 
    lineinfile: 
    dest: /path/to/file.txt 
    create: yes 
    line: "Path is {{ lookup('env', 'PATH') }}" 
    state: present 
0

基本上下面的任务会做:

- name: Ensure the file contains 'Path is $PATH' line 
    lineinfile: 
    dest: your_file 
    insertafter: EOF 
    regexp: "^Path is" 
    line: "Path is {{ ansible_env.PATH }}" 

但要记住:

  • 生成的线将包含价值用户用于在为非交互式shell创建的目标机器上运行Ansible任务。例如,在OS X上,默认情况下,它将不包含源自/etc/paths/etc/paths.d的路径,也不包含在.bash_profile中设置(更改)的值PATH

  • 使用lineinfile模块不会将一行添加到该文件的结束时,如果与Path is开头的行是已经存在别处(未在文件的结尾)在目标文件,它将取代它的值。