ansible ini_文件任务失败并关闭连接

ansible ini_文件任务失败并关闭连接,ansible,telegraf,Ansible,Telegraf,我正在尝试安装telegraf并更改其主配置文件/etc/telegraf/telegraf.conf的配置 安装成功,但更改配置文件时任务失败。这是tasks/main/yml文件 --- - name: install telegraf apt: pkg=telegraf state=installed become: true - name: changing conf file ini_file: path: /etc/telegraf/telegraf.conf

我正在尝试安装telegraf并更改其主配置文件
/etc/telegraf/telegraf.conf
的配置

安装成功,但更改配置文件时任务失败。这是tasks/main/yml文件

---

- name: install telegraf
  apt: pkg=telegraf state=installed
  become: true

- name: changing conf file
  ini_file:
    path: /etc/telegraf/telegraf.conf
    section: outputs.influxdb
    option: database
    value: ['http://localhost:8086']
但任务失败了

fatal: [192.168.122.62]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to 192.168.122.62 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_CQ_3uv/ansible_module_ini_file.py\", line 319, in <module>\r\n    main()\r\n  File \"/tmp/ansible_CQ_3uv/ansible_module_ini_file.py\", line 305, in main\r\n    (changed,backup_file,diff,msg) = do_ini(module, path, section, option, value, state, backup, no_extra_spaces, create)\r\n  File \"/tmp/ansible_CQ_3uv/ansible_module_ini_file.py\", line 268, in do_ini\r\n    ini_file = open(filename, 'w')\r\nIOError: [Errno 13] Permission denied: '/etc/telegraf/telegraf.conf'\r\n", "msg": "MODULE FAILURE", "rc": 0}

我不知道如何解决这个问题。需要帮助

我打赌你把
变成了
作为模块的参数,而不是任务的参数

它应该与操作名称位于相同的缩进级别:

- name: changing conf file
  ini_file:
    path: /etc/telegraf/telegraf.conf
    section: outputs.influxdb
    option: database
    value: ['http://localhost:8086']
  become: yes

嘿,但这导致了另一个问题,它没有编辑已经存在的块,而是在我运行它时添加了一个新块。可能节名需要额外的方括号吗?也尝试过了,它添加了另一个
[[outputs.influxdb]]
块。
- name: changing conf file
  ini_file:
    path: /etc/telegraf/telegraf.conf
    section: outputs.influxdb
    option: database
    value: ['http://localhost:8086']
  become: yes