ansible ini_file 任务失败并关闭连接
ansible ini_file task fails and closes connection
我正在尝试安装 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
is not a supported parameter in ini_file
.
这是 /etc/telegraf/telegraf.conf
文件中我要更改的部分。
[[outputs.influxdb]]
urls = ["http://192.168.1.9:8086"] # I want http://localhost:8086
database = "server-telegraf"
我不知道如何解决这个问题。需要帮助!
我敢打赌你把 become
作为模块的参数放错了位置,而不是任务的参数。
它应该与动作名称处于同一缩进级别:
- name: changing conf file
ini_file:
path: /etc/telegraf/telegraf.conf
section: outputs.influxdb
option: database
value: ['http://localhost:8086']
become: yes
我正在尝试安装 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
is not a supported parameter in ini_file
.
这是 /etc/telegraf/telegraf.conf
文件中我要更改的部分。
[[outputs.influxdb]]
urls = ["http://192.168.1.9:8086"] # I want http://localhost:8086
database = "server-telegraf"
我不知道如何解决这个问题。需要帮助!
我敢打赌你把 become
作为模块的参数放错了位置,而不是任务的参数。
它应该与动作名称处于同一缩进级别:
- name: changing conf file
ini_file:
path: /etc/telegraf/telegraf.conf
section: outputs.influxdb
option: database
value: ['http://localhost:8086']
become: yes