I want to add lines extracted from a file to a section , the line is not in the form of option=value, i use this program:
import configparser
f = open('inventory_file', 'r')
config = configparser.ConfigParser()
config.add_section('windows')
for line in f:
if line[4] == '0':
config.set('windows', line, 'None')
with open('example.cfg', 'w') as configfile:
config.write(configfile)
inventory_file:
W00VL9959061
W01V09908960
W01V09907745
W01V09907746
W01V09908317
W01V09907748
W00VL9968055
i got this result in example.cfg:
[windows]
w01v09908960
= None
w01v09907745
= None
w01v09907746
= None
w01v09908317
= None
w01v09907748
= None
i want something like this:
[windows]
w01v09908960
w01v09907745
w01v09907746
w01v09908317
w01v09907748
Any idea pls how i can modify my script to get the expected result
ConfigParserif you don't need a config file. Config files will have aparameter = valueformat; don't write a config file if you want an Ansible inventory file.