halfer halfer - 4 months ago 20
Ini Question

Is there a GNU/Linux command to write ini files?

I'm presently writing some documentation (specifically on how to set up Ansible with a local Vagrant machine) and I like to list commentary in the form of commands to issue. For example:



  1. Set up the SSH agent:

    ssh-agent bash
    ssh-add .vagrant/machines/default/virtualbox/private_key




However, sometimes I find I want to document a change in a config file, which is not so easy to describe. I presently do this:



  1. Configure Ansible to use port 2222 for Vagrant

    Modify /etc/ansible/ansible.cfg to use remote_port = 2222




I'd rather do something like this (a theoretical command) as it could be issued quickly and in a more automated fashion than reaching for a text editor:



  1. Configure Ansible to use port 2222 for Vagrant

    ansible-config remote_port 2222




This appears to be an ini file, so if the
ansible
binary doesn't support this (and I can't see that it does), is there a general Linux/Unix way to do this? Failing the above, how about:

iniwrite /etc/ansible/ansible.cfg defaults.remote_port 2222


Of course I could write a script of some kind, but it'd be better not to reinvent the wheel!

I am using Ubuntu 14.04 LTS.

Answer

I don't know about such a tool and it is definitely not part of the default toolchain you can expect to be installed on your user's systems.

You can use sed:

sed -i 's/^remote_port=.*/remote_port=2222/' ansible.cfg

All GNU/Linux users will understand that especially since you describe what it is doing.