Ansible系列(7)apt模块

apt模块

这个模块是ubuntu作为远端节点的OS的时候,用的最多的。Apt是啥就不多说了,ubuntu/debian的包管理工具。

模块参数

参数名 是否必须 默认值 选项值 参数说明
cache_valid_time no 如果update_cache参数起作用的时候,这个参数才会起作用。其用来控制update_cache的整体有效时间
deb no 这个用于安装远程机器上的.deb后缀的软件包
default_release no 等同于apt命令的-t选项,这里就不多说了
force no no yes/no 强制执行apt install/remove
install_recommends no Ture yes/no 这个参数可以控制远程电脑上是否只是下载软件包,还是下载后安装,默认参数为true,设置为false的时候光下载软件包,不安装
name no apt要下载的软件包名字,支持name=git=1.6 这种制定版本的模式
purge no yes/no 如果state参数值为absent,这个参数为yes的时候,将会强行干净的卸载
state no present latest/absent/present 定义软件包的最终状态,latest时为安装最新软件
update_cache no yes/no 当这个参数为yes的时候等于apt-get update
upgrade no yes yes/safe/full/dist 如果参数为yes或者safe,等同于apt-get upgrade.如果是full就是完整更新。如果是dist等于apt-get dist-upgrade。

使用案例

# 在安装foo软件包前更新然后安装foo
- apt: name=foo update_cache=yes

# 移除foo软件包
- apt: name=foo state=absent

# 安装foo软件包
- apt: name=foo state=present

# 安装foo 1.0软件包
- apt: name=foo=1.00 state=present

# 安装nginx最新的名字为squeeze-backport发布包,并且安装前执行更新
- apt: name=nginx state=latest default_release=squeeze-backports update_cache=yes

# 只下载openjdk-6-jdk最新的软件包,不安装
- apt: name=openjdk-6-jdk state=latest install_recommends=no

# 安装所有软件包到最新版本
- apt: upgrade=dist

# 更新apt-get的list
- apt: update_cache=yes

# 3600秒后停止update_cache
- apt: update_cache=yes cache_valid_time=3600

# 安装远程节点上的/tmp/mypackage.deb软件包
- apt: deb=/tmp/mypackage.deb

以上为官方网站上的常用用法举例。你会用了么?下一节将说说zypper

时间: 2024-07-30 20:20:01

Ansible系列(7)apt模块的相关文章

ansible系列第二篇(模块使用)

ansible系列第二篇(模块使用) 模块使用 设置ansible提权 在hosts文件加入sudo提权的密码: 18.18.23.102 ansible_become_pass='passwd' 执行: ansible test -S -R root -m shell -a "ls -l /" 查看ansible有那些模块: ansible-doc -l 获取各个模块详细帮助信息 ansible-doc -s ping ping模块: ansible test -m ping 从受控

自动化运维系列之Ansible命令应用基础(模块的应用)【持续更新中···】

自动化运维系列之Ansible命令应用基础(模块的应用) 模块简介 Ansible可以使用命令行方式进行自动化管理,基本语法如下: ansible <host-pattern> [-m module_name] [-a args] <host-pattern> 对哪些主机生效 [-m module_name] 需要使用的模块 [-a args] 模块特有的参数,这里在使用时需加单引号哦! Ansible的命令行管理工具都是由一系列模块.参数所支持的,可以在命令行后加上-h或--he

ansible学习系列2-ansible常用模块使用

1. 查看支持的模块 [[email protected] ~]# ansible-doc -l 这里我们看下ansible的支持的模块个数 [[email protected] ~]# ansible-doc -l |wc -l #查看支持的模块个数 1039 [[email protected] ~]# ansible --version #查看我们的ansible版本号 ansible 2.3.1.0 config file = /etc/ansible/ansible.cfg confi

Ansible系列命令用法详解与使用

Ansible系列命令用法与使用 在上一个文章中已经完成了Ansible的安装,这片文章主要的用来记录Ansible一些命令的用法详解及其使用场景.好了非话不多说,'上菜吧'. Ansible命令行执行方式有Ad-hoc.Ansible-playbook两种方式.Web化执行方式其官方提供了付费产品Tower(10台以内免费),个人的话可以基于API开发类似的Web化产品.此篇文章主要针对于Ad-hoc.Ansible-playbook两种方式做详细介绍. 什么是Ad-hoc.Ansible-p

ansible常用命令及模块的使用方法

ansible是指令核心部分,其主要用于执行ad-hoc(点对点)命令,即单条命令.默认后面需要跟主机和选项部分,默认不指定模块时,使用的是command模块. 2. 默认使用的模块是可以在ansible.cfg 中进行修改的. /etc/ansible/ansible.cfg ansible常用命令解析: 查看当前 ansible 都支持哪些模块: ansible-doc -l 查看某一模块可以使用的参数:ansible-doc -s copy (eg:copy模块) ansible用法: a

22Python标准库系列之Redis模块

Python标准库系列之Redis模块 What is redis? Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, b

Ansible(三)模块

1.查看模块帮助 ~]# man-ansible-doc(查看Ansible自带的模块文档信息) ~]# ansible-doc -l(列出支持的所有模块) ~]# ansible-doc -s MODULE_NAME(查看模块支持的配置指令) 2.使用语法 ansible <host-pattern> [-m module_name] [-a args] [options] OPTIONS host-pattern:对哪些主机生效,支持组名 -f:启动并发线程数,指定一批处理主机数量 -m:

11Python标准库系列之configparser模块

Python标准库系列之configparser模块 This module provides the ConfigParser class which implements a basic configuration language which provides a structure similar to what's found in Microsoft Windows INI files. You can use this to write Python programs which

9Python标准库系列之time模块

Python标准库系列之time模块 This module provides various functions to manipulate time values. 方法名 说明 time.sleep(int) 等待时间 time.time() 输出时间戳,从1970年1月1号到现在用了多少秒 time.ctime() 返回当前的系统时间 time.gmtime() 将时间戳转换成struct_time格式 time.localtime() 以struct_time格式返回本地时间 time