Apache2 Ansible lineinfile跳过线
在我的Ansible脚本中,我使用循环向来宾操作系统上的apache2.conf文件添加行。lineinfile模块插入除最后一行之外的每一行Apache2 Ansible lineinfile跳过线,apache2,vagrant,ubuntu-14.04,ansible,Apache2,Vagrant,Ubuntu 14.04,Ansible,在我的Ansible脚本中,我使用循环向来宾操作系统上的apache2.conf文件添加行。lineinfile模块插入除最后一行之外的每一行。为什么Ansible跳过了最后一行?谢谢 - name: test lineinfile: dest: /etc/apache2/apache2.conf line: "{{ item.line }}" with_items: - { line: <Directory /vagrant> } - {
。为什么Ansible跳过了最后一行?谢谢
- name: test
lineinfile:
dest: /etc/apache2/apache2.conf
line: "{{ item.line }}"
with_items:
- { line: <Directory /vagrant> }
- { line: Options Indexes FollowSymLinks }
- { line: AllowOverride All }
- { line: Require all granted }
- { line: </Directory> }
notify:
- restart apache2
-名称:测试
线条填充:
dest:/etc/apache2/apache2.conf
行:“{item.line}”
有以下项目:
-{line:}
-{line:Options索引FollowSymLinks}
-{line:AllowOverride All}
-{line:需要所有已授予的}
-{line:}
通知:
-重新启动apache2
这是不可复制的。您确定文件中没有更高的
标记吗
以下是我测试的任务:
- name: test
lineinfile:
dest: foo.conf
line: "{{ item.line }}"
with_items:
- { line: <Directory /vagrant> }
- { line: Options Indexes FollowSymLinks }
- { line: AllowOverride All }
- { line: Require all granted }
- { line: </Directory> }
另一方面,使用
lineinfle
通常表示该文件(本例中为apache2.conf)不在配置管理中。很多可怕的事情可能会发生,这将摆脱。在配置管理中使用apache2.conf会更好。(例如,使用Ansible部署它)。或者,您至少可以使用conf.d
文件,以便Ansible可以“拥有”整个文件。我认为这是模块lineinfle
中的一个错误
行
在文件apache2.conf中出现,Ansiblelineinfle
跳过它
我已向Ansible团队报告。注意,自Ansible 2.0(2016年1月发布,在提出此问题后)起,最好使用BlockInfle来实现这一点:
- name: insert vagrant directory
blockinfile:
path: /etc/apache2/apache2.conf
block: |
<Directory /vagrant>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Match User ansible-agent
PasswordAuthentication no
-名称:插入流浪者目录
区块填充:
路径:/etc/apache2/apache2.conf
区块:|
选项索引跟随符号链接
允许超越所有
要求所有授权
匹配用户代理
密码验证号
ref:强调“在配置管理中使用apache2.conf会更好”,我建议使用模板模块。
- name: insert vagrant directory
blockinfile:
path: /etc/apache2/apache2.conf
block: |
<Directory /vagrant>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Match User ansible-agent
PasswordAuthentication no