我有这段代码
1 - hosts: webservers
2 remote_user: user
3 become: yes
4 become_method: sudo
5 tasks:
6
7 - name: Adding hosts to file
8 lineinfile:
9 dest=/etc/hosts
10 state=present
11 insertafter=EOF
12 line="someline1"
13 with_items:
14 - line="someline2"
15 - line="someline3"
16 - line="someline4"
17 - line="someline5"
然而,当脚本运行时,它只会经历两个案例,就像这样,并没有告诉我原始lineinfile函数中的行 -
PLAY [webservers] *************************************************************
GATHERING FACTS ***************************************************************
ok: [user@11.11.11.11]
TASK: [Adding hosts to file] **************************************************
ok: [user@11.11.11.11] => (item=line="someline2")
ok: [user@11.11.11.11] => (item=line="someline3")
ok: [user@11.11.11.11] => (item=line="someline4")
ok: [user@11.11.11.11] => (item=line="someline5")
PLAY RECAP ********************************************************************
user@11.11.11.11 : ok=2 changed=0 unreachable=0 failed=0
Someline3,4和5未添加到文件中。知道问题可能是什么?
答案 0 :(得分:2)
您每次都在检查同一行。改变它以满足您的需求:
call(["depends"] + DEP)