我有以下代码来设置PostgreSQL:
- name: mute install log1
lineinfile:
dest: /etc/yum.repos.d/CentOS-Base.repo
insertafter: '{{ item }}'
line: 'exclude=postgresql*'
with_items:
- '^\[base\]'
- '^\[updates\]'
然而,Ansible只根据项目列表中的顺序添加一行。如何在一个文件中添加两行相同的行?
答案 0 :(得分:1)
以下两种方法可以避免多次lineinfile
调用,这是一种反模式。
将CentOS-Base.repo复制到您的ansible files
目录。添加两个exclude
行,然后发布该文件:
$ cat CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
...
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
exclude=postgres*
#released updates
[updates]
name=CentOS-$releasever - Updates
...
和
- copy: src=CentOS-Base.repo dest=/etc/yum.repos.d/CentOS-Base.repo owner=root group=root mode=0644
$ cat files/exclude-postgres.repo
[base]
exclude=postgresql*
[updates]
exclude=postgresql*
和
- copy: src=exclude-postgres.repo dest=/etc/yum.repos.d/exclude-postgres.repo owner=root group=root mode=0644
我认为还有第三种方式。我可能会在以后添加它。