使用Ansible配置apache2.conf变量时,如何去除配置项中的等号?
Apache配置项无等号设置问题及解决方法
我编写了一个简单的Ansible Playbook,尝试使用community.general.ini_file模块配置apache2.conf中的两个超时参数:
- name: 设置Apache超时时间 community.general.ini_file: path: /etc/apache2/apache2.conf section: null option: Timeout value: 900 state: present exclusive: true - name: 设置代理超时时间 community.general.ini_file: path: /etc/apache2/apache2.conf section: null option: ProxyTimeout value: 900 state: present exclusive: true
但执行后生成的配置项自动带上了等号,不符合预期格式:
Timeout = 900 ProxyTimeout = 900
我需要生成不带等号的配置格式:
Timeout 900 ProxyTimeout 900
已找到解决方法
改用ansible.builtin.lineinfile模块可以实现需求:
- name: 设置Timeout参数 ansible.builtin.lineinfile: path: /etc/apache2/apache2.conf regexp: '^Timeout ' insertafter: '^#Timeout ' line: Timeout 900 - name: 设置ProxyTimeout参数 ansible.builtin.lineinfile: path: /etc/apache2/apache2.conf regexp: '^ProxyTimeout ' insertafter: '^Timeout ' line: ProxyTimeout 900
内容的提问来源于stack exchange,提问作者Aidvi
相关产品推荐
相关产品推荐

