【问题标题】:Setting apache2.conf variables with Ansible problem使用 Ansible 问题设置 apache2.conf 变量
【发布时间】:2022-10-14 22:19:44
【问题描述】:

我有一个简单的 ansible 剧本,它设置了两个 ini 变量。

- name: set Apache timeout
  community.general.ini_file:
    path: /etc/apache2/apache2.conf
    section: null
    option: Timeout
    value: 900
    state: present
    exclusive: true

- name: set Proxy timeout
  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

编辑这解决了它。

- name: set Timeout
  ansible.builtin.lineinfile:
    path: /etc/apache2/apache2.conf
    regexp: '^Timeout '
    insertafter: '^#Timeout '
    line: Timeout 900

- name: set Proxy timeout
  ansible.builtin.lineinfile:
    path: /etc/apache2/apache2.conf
    regexp: '^ProxyTimeout '
    insertafter: '^Timeout '
    line: ProxyTimeout 900

【问题讨论】:

  • apache2.conf不是 ini 格式,因此您没有使用正确的模块来满足您的要求。
  • 你知道用于 conf 文件的模块吗?

标签: ansible ansible-2.x


【解决方案1】:

据我所知,这个文件没有遵循 INI 结构。因此,“ini_file”模块可能是错误的。

就个人而言,我建议使用带有正则表达式的“lineinfile”模块。

(从模块页面复制此示例 - 使用上面的链接获取更多信息)

- name: Ensure the default Apache port is 8080
  ansible.builtin.lineinfile:
    path: /etc/httpd/conf/httpd.conf
    regexp: '^Listen '
    insertafter: '^#Listen '
    line: Listen 8080

【讨论】:

  • 谢谢我工作得很好。
猜你喜欢
  • 2015-10-24
  • 2016-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-31
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多