You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 19:55:17