ansible之fetch模块

fetch官方链接http://docs.ansible.com/ansible/fetch_module.html

文件拉取模块主要是将远程主机中的文件拷贝到本机中,和copy模块的作用刚刚相反,并且在保存的时候使用hostname来进行保存,当文件不存在的时候,会出现错误,除非设置了选项fail_on_missing为yes

fetch用法选项

[[email protected] ~]# ansible-doc -s fetch

less 436

Copyright (C) 1984-2009 Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.

For information about the terms of redistribution,

see the file named README in the less distribution.

Homepage: http://www.greenwoodsoftware.com/less

- name: Fetches a file from remote nodes

action: fetch

dest=                  # A directory to save the file into. For example, if the `dest‘ directory is `/backup‘ a `src‘ file

named `/etc/profile‘ on host `host.example.com‘, would be saved

into `/backup/host.example.com/etc/profile‘

fail_on_missing        # Makes it fails when the source file is missing.

flat                   # Allows you to override the default behavior of appending hostname/path/to/file to the

destination.  If dest ends with ‘/‘, it will use the basename of

the source file, similar to the copy module. Obviously this is

only handy if the filenames are unique.

src=\‘#\‘"                 # The file on the remote system to fetch. This `must‘ be a file, not a directory. Recursive

fetching may be supported in a later release.

validate_checksum      # Verify that the source and destination checksums match after the files are fetched.

dest:用来存放文件的目录,例如存放目录为backup,源文件名称为/etc/profile在主机pythonserver中,那么保存为/backup/pythonserver/etc/profile

Fail_on_missing:当源文件不存在的时候,标识为失败

Flat:允许覆盖默认行为从hostname/path到/file的,如果dest以/结尾,它将使用源文件的基础名称

Src:在远程拉取的文件,并且必须是一个file,不能是目录

Validate_checksum:当文件fetch之后进行md5检查

示例如下

时间: 2024-08-11 20:54:28

ansible之fetch模块的相关文章

02.ansible的常用模块

可以从ansible-doc -l | grep来找出想要的模块.再使用ansible-doc -s module_name来查看此模块的用法.官方模块列表和说明:https://docs.ansible.com/ansible/latest/modules_by_category.html 关于模块的使用方法,需要注意的是"state".很多模块都会有该选项,且其值几乎都包含有"present"和"absent",表示肯定和否定的意思. ans

ansible之setup模块常用的信息

ansible的setup模块非常好用,但给出的信息十分全面,有时候我们并不需要全部的信息. 过滤出指定的信息:例->ansible all -m setup -a "filter=ansible_os_family" ansible_all_ipv4_addresses:仅显示ipv4的信息 ansible_devices:仅显示磁盘设备信息 ansible_distribution:显示是什么系统,例:centos,suse等 ansible_distribution_ver

ansible执行shell模块和command模块报错| FAILED | rc=127 >> /bin/sh: lsof: command not found和| rc=2 >> [Errno 2] No such file or directory

命令: ansible -i hosts_20 st  -m shell -a 'service zabbix_agentd star'  -K --become ansible -i hosts_20 st  -m shell -a 'lsof -i:10050'  -K --become 在shell模块报错:| FAILED | rc=127 >>/bin/sh: lsof: command not found 在command模块报错:| rc=2 >>[Errno 2]

Ansible运行setup模块卡住不动

一. 问题 今天运行Ansible时发现有台机器在执行setup时卡在不动,等了好几分钟才执行出来. 二. 分析问题 Ansible中setup模块的执行过程,它是将setup模块的python脚本拷贝到ansible管控主机,然后在管控主机上执行python脚本获取主机基本信息,在返回给ansible.查看执行setup的主机,看到执行的python进程处于D状态.也就是不可中断状态.而获取主机上资源时,如果文件系统有问题是最容易卡住的.而那台主机上是挂载了windows的samba文件系统.

自动化运维之Ansible安装与模块应用

自动化运维之Ansible Ansible概述 由于互联网快速展导致产品更新换代速度逐渐加快,运维人员每天都要进行大量维护操作,人就按照传统方式进行维护会使工作效率低下,只是,部署自动化运维就尽可能安全,高校的完成工作 一般会把自动化运维工具划分为两类 (一)需要使用代理工具的,也就是基于专用的Agent程序完成管理功能,如:Puppet.Func.Zabbix等(二)不需要配置代理工具,可以直接基于SSH服务来管理完成,如:Ansible,Fabric等 下面介绍几款空能和类似的自动化运维工具

自动化运维之Ansible应用基础模块(超详细)

Ansible是一种基于模块进行工作的框架结构.批量部署能力就是由Ansible所运行的模块实现的.简而言之Ansible是基于"模块"完成各种"任务"的. Ansible常用的核心模块 模块的基本语法如下 ansible [主机] [-m 模块] [-a args] //命令格式 # ansible-doc -l //列出所有已安装的模块 注:按q退出 # ansible-doc -s yum //-s列出yum模块描述信息和操作动作 1.command 模块 c

超详细Ansible安装及模块详解

简介:ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能. ansible是基于模块工作的,本身没有批量部署的能力.真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架.主要包括: (1).连接插件connection plugins:负责和被监控端实现通信; (2).host inventory:指定操作的主机,

ansible的常见模块用法

配置文件详解: 1,主配置文件:/etc/asiable/ansiable.cfg module_name =command ##ansible的默认模块是command模块,但是在使用的时候非常的有局限性,建议改成shell模块 host_key_checking = False ##检查对应要控制主机的的host_key,建议取消注释,以减轻管理时需要输入的密码 log_path = /var/log/ansible.log ##ansible的登录日志文件所在的位置 executable

运维自动化神器ansible之user模块

运维自动化神器ansible之user模块 一.概述 ?user模块 可管理远程主机上的 用户,比如创建用户.修改用户.删除用户.为用户创建密钥对等操作. 二.参数介绍 ? name: 用于指定操作的 user,必须项. uid: 用于指定 user 的 UID,默认为空. _non_unique:_ 与uid参数一起使用,允许改变UID为非唯一值. group: 参数用于指定用户 主组.默认值为空,为空时创建的用户组名跟用户名一致. groups: 参数用于指定用户属组,可以在创建用户时指定用