ansible ini_file任务失败并关闭连接

时间:2017-07-05 07:20:49

标签: 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
    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}

这是一个权限被拒绝的错误,所以我尝试在任务中添加become: true,但后来却说become中的ini_file不是受支持的参数。

这是我要更改的/etc/telegraf/telegraf.conf文件的部分。

[[outputs.influxdb]]
  urls = ["http://192.168.1.9:8086"] # I want http://localhost:8086 
  database = "server-telegraf" 

我没有得到如何解决这个问题。需要帮助!

1 个答案:

答案 0 :(得分:1)

我敢打赌你把become放错了作为模块的参数,而不是任务的。

它应与动作名称在同一缩进级别:

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