apt_repository - Add and remove APT repositories


  • Add or remove an APT repositories in Ubuntu and Debian.

Requirements (on host that executes module)

  • python-apt (python 2)
  • python3-apt (python 3)


parameter required default choices comments
(added in 2.3)
Override the distribution codename to use for PPA repositories. Should usually only be set when working with a PPA on a non-Ubuntu target (e.g. Debian or Mint)
(added in 2.1)
Sets the name of the source list file in sources.list.d. Defaults to a file name based on the repository source url. The .list extension will be automatically added.
(added in 1.6)
no 420
The octal mode for newly created files in sources.list.d
yes none
A source string for the repository.
no present
  • absent
  • present
A source string state.
no yes
  • yes
  • no
Run the equivalent of apt-get update when a change occurs. Cache updates are run after making changes.
(added in 1.8)
no yes
  • yes
  • no
If no, SSL certificates for the target repo will not be validated. This should only be used on personally controlled sites using self-signed certificates.


# Add specified repository into sources list.
- apt_repository:
    repo: deb hardy partner
    state: present

# Add specified repository into sources list using specified filename.
- apt_repository:
    repo: deb stable main
    state: present
    filename: 'google-chrome'

# Add source repository into sources list.
- apt_repository:
    repo: deb-src hardy partner
    state: present

# Remove specified repository from sources list.
- apt_repository:
    repo: deb hardy partner
    state: absent

# Add nginx stable repository from PPA and install its signing key.
# On Ubuntu target:
- apt_repository:
    repo: 'ppa:nginx/stable'

# On Debian target
- apt_repository:
    repo: 'ppa:nginx/stable'
    codename: 'trusty'



  • This module works on Debian, Ubuntu and their derivatives.
  • This module supports Debian Squeeze (version 6) as well as its successors.


This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Maintenance Info

For more information about Red Hat’s this support of this module, please refer to this knowledge base article<>

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Testing Ansible and Developing Modules.