我想在文件中使用lineinfile
添加或編輯多行但不起作用。我使用下面的代碼,沒有運氣編號:ansible: lineinfile for several lines?Ansible fileinline不能與循環一起工作
# vim /etc/ansible/playbook/test-play.yml
- hosts: tst.wizvision.com
tasks:
- name: change of line
lineinfile:
dest: /root/test.txt
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
backrefs: yes
with_items:
- { regexp: '^# line one', line: 'NEW LINE ONE' }
- { regexp: '^# line two', line: 'NEW LINE TWO' }
Ansible錯誤:
# ansible-playbook test-2.yml
TASK [線的變化] ************** ********************************************
fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'item' is undefined\n\nThe error appears to have been in '/etc/ansible/playbook/test-2.yml': line 3, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: change of line\n^here\n"}
非常感謝。它現在有效。浪費了我很多時間...... –
沒問題,很高興它爲你工作! :) – rk2