ansible / ansible.builtin / v2.9.7 / module / apt Manages apt-packages | "added in version" 0.0.2 of ansible.builtin" Authors: Matthew Williams (@mgwilliams) stableinterface | supported by coreansible.builtin.apt (v2.9.7) — module
pip
Install with pip install ansible==2.9.7
Manages I(apt) packages (such as for Debian/Ubuntu).
- name: Install apache httpd (state=present is optional) apt: name: apache2 state: present
- name: Update repositories cache and install "foo" package apt: name: foo update_cache: yes
- name: Remove "foo" package apt: name: foo state: absent
- name: Install the package "foo" apt: name: foo
- name: Install a list of packages apt: pkg: - foo - foo-tools
- name: Install the version '1.00' of package "foo" apt: name: foo=1.00
- name: Update the repository cache and update package "nginx" to latest version using default release squeeze-backport apt: name: nginx state: latest default_release: squeeze-backports update_cache: yes
- name: Install latest version of "openjdk-6-jdk" ignoring "install-recommends" apt: name: openjdk-6-jdk state: latest install_recommends: no
- name: Upgrade all packages to the latest version apt: name: "*" state: latest
- name: Update all packages to the latest version apt: upgrade: dist
- name: Run the equivalent of "apt-get update" as a separate step apt: update_cache: yes
- name: Only run "update_cache=yes" if the last one is more than 3600 seconds ago apt: update_cache: yes cache_valid_time: 3600
- name: Pass options to dpkg on run apt: upgrade: dist update_cache: yes dpkg_options: 'force-confold,force-confdef'
- name: Install a .deb package apt: deb: /tmp/mypackage.deb
- name: Install the build dependencies for package "foo" apt: pkg: foo state: build-dep
- name: Install a .deb package from the internet. apt: deb: https://example.com/python-ppq_0.1-1_all.deb
- name: Remove useless packages from the cache apt: autoclean: yes
- name: Remove dependencies that are no longer required apt: autoremove: yes
deb: description: - Path to a .deb package on the remote machine. - If :// in the path, ansible will attempt to download deb before installing. (Version added 2.1) - Requires the C(xz-utils) package to extract the control file of the deb package to install. required: false version_added: '1.6' version_added_collection: ansible.builtin name: aliases: - package - pkg description: - A list of package names, like C(foo), or package specifier with version, like C(foo=1.0). Name wildcards (fnmatch) like C(apt*) and version wildcards like C(foo=1.0*) are also supported. force: default: 'no' description: - 'Corresponds to the C(--force-yes) to I(apt-get) and implies C(allow_unauthenticated: yes)' - This option will disable checking both the packages' signatures and the certificates of the web servers they are downloaded from. - This option *is not* the equivalent of passing the C(-f) flag to I(apt-get) on the command line - '**This is a destructive operation with the potential to destroy your system, and it should almost never be used.** Please also see C(man apt-get) for more information.' type: bool purge: default: 'no' description: - Will force purging of configuration files if the module state is set to I(absent). type: bool state: choices: - absent - build-dep - latest - present - fixed default: present description: - Indicates the desired package state. C(latest) ensures that the latest version is installed. C(build-dep) ensures the package build dependencies are installed. C(fixed) attempt to correct a system with broken dependencies in place. upgrade: choices: - dist - full - 'no' - safe - 'yes' default: 'no' description: - If yes or safe, performs an aptitude safe-upgrade. - If full, performs an aptitude full-upgrade. - If dist, performs an apt-get dist-upgrade. - 'Note: This does not upgrade a specific package, use state=latest for that.' - 'Note: Since 2.4, apt-get is used as a fall-back if aptitude is not present.' version_added: '1.1' version_added_collection: ansible.builtin autoclean: default: 'no' description: - If C(yes), cleans the local repository of retrieved package files that can no longer be downloaded. type: bool version_added: '2.4' version_added_collection: ansible.builtin autoremove: default: 'no' description: - If C(yes), remove unused dependency packages for all module states except I(build-dep). It can also be used as the only option. - Previous to version 2.4, autoclean was also an alias for autoremove, now it is its own separate command. See documentation for further information. type: bool version_added: '2.1' version_added_collection: ansible.builtin policy_rc_d: default: null description: - Force the exit code of /usr/sbin/policy-rc.d. - For example, if I(policy_rc_d=101) the installed package will not trigger a service start. - If /usr/sbin/policy-rc.d already exist, it is backed up and restored after the package installation. - If C(null), the /usr/sbin/policy-rc.d isn't created/changed. type: int version_added: '2.8' version_added_collection: ansible.builtin dpkg_options: default: force-confdef,force-confold description: - Add dpkg options to apt command. Defaults to '-o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold"' - Options should be supplied as comma separated list only_upgrade: default: 'no' description: - Only upgrade a package if it is already installed. type: bool version_added: '2.1' version_added_collection: ansible.builtin update_cache: default: 'no' description: - Run the equivalent of C(apt-get update) before the operation. Can be run as part of the package installation or as a separate step. type: bool force_apt_get: default: 'no' description: - Force usage of apt-get instead of aptitude type: bool version_added: '2.4' version_added_collection: ansible.builtin default_release: description: - Corresponds to the C(-t) option for I(apt) and sets pin priorities cache_valid_time: default: 0 description: - Update the apt cache if its older than the I(cache_valid_time). This option is set in seconds. - As of Ansible 2.4, if explicitly set, this sets I(update_cache=yes). install_recommends: aliases: - install-recommends description: - Corresponds to the C(--no-install-recommends) option for I(apt). C(yes) installs recommended packages. C(no) does not install recommended packages. By default, Ansible will use the same defaults as the operating system. Suggested packages are never installed. type: bool allow_unauthenticated: default: 'no' description: - Ignore if packages cannot be authenticated. This is useful for bootstrapping environments that manage their own apt-key setup. - 'C(allow_unauthenticated) is only supported with state: I(install)/I(present)' type: bool version_added: '2.1' version_added_collection: ansible.builtin
cache_update_time: description: time of the last cache update (0 if unknown) returned: success, in some cases sample: 1425828348000 type: int cache_updated: description: if the cache was updated or not returned: success, in some cases sample: true type: bool stderr: description: error output from apt returned: success, when needed sample: 'AH00558: apache2: Could not reliably determine the server''s fully qualified domain name, using 127.0.1.1. Set the ''ServerName'' directive globally to ...' type: str stdout: description: output from apt returned: success, when needed sample: 'Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: apache2-bin ...' type: str