NEWB howto modify /etc/apt/sources.list

I am new to Ansible and looking for a simple way to modify the /etc/apt/sources.list file in Debian to include the contrib repo.

I seem to find ways to pull a file down, but how does one edit an existing conf file?

I would advise using the apt_repository module, template or even copy
modules, but for existing files you might need to use lineinfile.

So Brian I am trying apt_repositoy but getting errors.

If I am using Debian Wheezy and want to add the non-free repo, I would expect that I should use the following ad-hoc statement:

ansible test -m apt_repository -a ‘repo=deb http://ftp.us.debian.org/debian/ wheezy main contrib state=present’

This produces an error about parameters, so I tried the following as well:

ansible test -m apt_repository -a ‘repo=“deb http://ftp.us.debian.org/debian/ wheezy main contrib” state=present’

Also does not work… Any suggestions?

​it might help to paste those exact errors

I would be happy too; however; I am not able to cut and paste from a Fusion window, and if I ssh into my Ansible control node the environment variable for Ansible is not persistant.

Any suggestions?

​a link to a screen​shot?

root@ansibleControl:~# ansible mediaserver -m apt_repository -a ‘repo=deb http://ftp.us.debian.org/debian/ wheezy main contrib state=present’

^C

root@ansibleControl:~# ansible mediaserver -m apt_repository -a ‘repo=deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free state=present’

192.168.154.243 | FAILED >> {
“failed”: true,
“msg”: “this module requires key=value arguments ([‘repo=deb’, ‘http://ftp.us.debian.org/debian/’, ‘wheezy’, ‘main’, ‘contrib’, ‘non-free’, ‘state=present’])”
}

So this works, or at least reports that it was successful:

root@ansibleControl:~# ansible mediaserver -m apt_repository -a “repo=‘deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free’ state=present”
192.168.154.243 | success >> {
“changed”: false,
“repo”: “deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free”,
“state”: “present”
}

However when I goto the .243 server the non-free repo is not listed.

​your quoting is bad here

​​ansible mediaserver -m apt_repository -a 'repo="deb
http://ftp.us.debian.org/debian/ wheezy main contrib non-free"
state=present'

right, so the following does not throw an error:

ansible mediaserver -m apt_repository -a “repo=‘deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free’ state=present”

but it does not change anything either.