ansible plugins简介

ansible插件是增强ansible的核心功能的代码片段,ansible使用插件架构来实现丰富,灵活和可扩展的功能集。

Ansible提供了许多方便的插件,您可以轻松编写自己的插件。
下边简单介绍Ansible包含的各种插件(插件具体用法请参考官方文档或者ansible-doc):

1、action插件

Action插件与模块一起执行PlayBook任务所需的操作。它们通常在后台自动执行,在模块执行之前进行必要的工作。
“normal” action插件 用于尚未拥有action插件的模块。
您可以启用一个自定义操作插件,方法是将其放置到与role中的play相邻的action_plugins目录中,
当使用关联模块时,Action插件默认执行;不需要采取任何行动

2、cache插件

缓存插件实现的后端缓存机制,可以使ansible存储获得的facts和inventory元数据,不必再从源头检索这些数据,而降低性能。
默认的缓存插件是memory plugin,它只缓存ansible目前执行的数据,其他持久存储的插件也可以缓存数据
  • jsonfile - JSON formatted files.
  • memcached - Use memcached DB for cache
  • memory - RAM backed, non persistent
  • mongodb - Use MongoDB for caching
  • pickle - Pickle formatted files.
  • redis - Use Redis DB for cache
  • yaml - YAML formatted files.

3、callback插件

回调插件可以在响应事件时向Ansible添加新行为。
默认情况下,回调插件控制运行命令行程序时看到的大部分输出,
但也可用于添加其他输出,与其他工具集成并将事件整理到存储后端。
  • actionable - shows only items that need attention
  • context_demo - demo callback that adds play/task context
  • debug - formated stdout/stderr display
  • default - default Ansible screen output
  • dense - minimal stdout output
  • foreman - Sends events to Foreman
  • full_skip - suppresses tasks if all hosts skipped
  • hipchat - post task events to hipchat
  • jabber - post task events to a jabber server
  • json - Ansible screen output as JSON
  • junit - write playbook output to a JUnit file.
  • log_plays - write playbook output to log file
  • logentries - Sends events to Logentries
  • logstash - Sends events to Logstash
  • mail - Sends failure events via email
  • minimal - minimal Ansible screen output
  • null - Don’t display stuff to screen
  • oneline - oneline Ansible screen output
  • osx_say - oneline Ansible screen output
  • profile_roles - adds timing information to roles
  • profile_tasks - adds time information to tasks
  • selective - only print certain tasks
  • skippy - Ansible screen output that ignores skipped status
  • slack - Sends play events to a Slack channel
  • stderr - Splits output, sending failed tasks to stderr
  • syslog_json - sends JSON events to syslog
  • timer - Adds time to play stats
  • tree - Save host events to files
  • unixy - condensed Ansible output
  • yaml - yaml-ized Ansible screen output

4、inventory插件

清单插件允许用户指向数据源,以便通过-i  /path/to/file和/ 或-i 'host1,host2 命令行参数
或其他配置来源编译Ansible用于定位任务的主机清单。
个人觉得ini最好用
  • advanced_host_list - Parses a ‘host list’ with ranges
  • auto - Loads and executes an inventory plugin specified in a YAML config
  • aws_ec2 - ec2 inventory source
  • constructed - Uses Jinja2 to construct vars and groups based on existing inventory.
  • host_list - Parses a ‘host list’ string
  • ini - Uses an Ansible INI file as inventory source.
  • k8s - Kubernetes (K8s) inventory source
  • openshift - OpenShift inventory source
  • openstack - OpenStack inventory source
  • script - Executes an inventory script that returns JSON
  • virtualbox - virtualbox inventory source
  • yaml - Uses a specifically YAML file as inventory source.

5、lookup插件

查找插件允许Ansible从外部来源访问数据。这可以包括:联系外部数据存储和服务,读取文件系统。
查找插件返回的数据可以使用Ansible中的标准模板系统提供,通常用于从这些系统中加载包含信息的变量或模板。
lookups是Jinja2模板语言的Ansible特定扩展。
  • aws_account_attribute - Look up AWS account attributes.
  • aws_service_ip_ranges - Look up the IP ranges for services provided in AWS such as EC2 and S3.
  • aws_ssm - Get the value for a SSM parameter or all parameters under a path.
  • cartesian - returns the cartesian product of lists
  • chef_databag - fetches data from a Chef Databag
  • config - Lookup current Ansilbe configuration values
  • conjur_variable - Fetch credentials from CyberArk Conjur.
  • consul_kv - Fetch metadata from a Consul key value store.
  • credstash - retrieve secrets from Credstash on AWS
  • csvfile - read data from a TSV or CSV file
  • cyberarkpassword - get secrets from CyberArk AIM
  • dict - returns key/value pair items from dictionaries
  • dig - query DNS using the dnspython library
  • dnstxt - query a domain(s)’s DNS txt fields
  • env - read the value of environment variables
  • etcd - get info from etcd server
  • file - read file contents
  • fileglob - list files matching a pattern
  • filetree - recursively match all files in a directory tree
  • first_found - return first file found from list
  • flattened - return single list completely flattened
  • hashi_vault - retrieve secrets from HasihCorp’s vault
  • hiera - get info from hiera data
  • indexed_items - rewrites lists to return ‘indexed items’
  • ini - read data from a ini file
  • inventory_hostnames - list of inventory hosts matching a host pattern
  • items - list of items
  • k8s - Query the K8s API
  • keyring - grab secrets from the OS keyring
  • lastpass - fetch data from lastpass
  • lines - read lines from command
  • list - simply returns what it is given.
  • mongodb - lookup info from MongoDB
  • nested - composes a list with nested elements of other lists
  • nios - Query Infoblox NIOS objects
  • nios_next_ip - Return the next available IP address for a network
  • openshift - Query the OpenShift API
  • password - retrieve or generate a random password, stored in a file
  • passwordstore - manage passwords with passwordstore.org’s pass utility
  • pipe - read output from a command
  • random_choice - return random element from list
  • redis - fetch data from Redis
  • redis_kv - fetch data from Redis
  • sequence - generate a list based on a number sequence
  • shelvefile - read keys from Python shelve file
  • subelements - traverse nested key from a list of dictionaries
  • template - retrieve contents of file after templating with Jinja2
  • together - merges lists into syncronized list
  • url - return contents from URL
  • vars - Lookup templated value of variables

6、shell插件

Shell插件可以确保Ansible运行的基本命令格式正确,可与目标机器一起使用,并允许用户配置某些与Ansible执行任务相关的行为
  • csh - C shell (/bin/csh)
  • fish - fish shell (/bin/fish)
  • powershell - Windows Powershell
  • sh - POSIX shell (/bin/sh)

7、strategy插件

策略插件通过处理play和hosts调度 来控制play执行的流程。
  • debug - Executes tasks in interactive debug session.
  • free - Executes tasks on each host independently
  • linear - Executes tasks in a linear fashion

8、vars插件

Vars插件将额外的变量注入到Ansible中运行,这些运行不是来自库存源,剧本或命令行。
Playbook使用vars插件构建像'host_vars'和'group_vars'的工作目录。
Vars插件在Ansible 2.0中部分实现,并被重写为从Ansible 2.4开始全面实施。
Ansible附带的host_group_vars插件可以从主机变量和组变量中读取变量。
  • host_group_vars - In charge of loading group_vars and host_vars

9、filters

Ansible中的过滤器来自Jinja2,用于转换模板表达式中的数据。
Jinja2附带很多过滤器。请参阅官方Jinja2模板文档中的内置过滤器。
考虑到 模板产生 在Ansible控制器上,而不是在任务的目标主机上,所以过滤器也在控制器上执行,因为它们处理本地数据。
除了jinja2,Ansible附带自己的产品,并允许用户添加他们自己的自定义过滤器。
 

10、tests

Jinja中的tests是评估模板表达式,并返回True或False的一种方式,Jinja附带许多这些。在官方Jinja模板文档中查看内置测试。
tests和filters之间的主要区别在于Jinja tests用于比较,而filters用于数据处理,并且在jinja中有不同的应用程序,如map()和select()来选择列表中的项目。
像所有模板一样,tests总是在Ansible控制器上执行,而不是在任务的目标上执行,因为他们测试本地数据。
除了jinjia2 tests,Ansible提供更多功能,用户可以自己轻松创建。
 

11、插件过滤配置

Ansible 2.5为站点管理员添加了模块黑名单,用于禁用Ansible的某些模块。
这是通过yaml配置文件配置的(默认为/etc/ansible/plugin_filters.yml)。该文件的格式是:
---
filter_version: '1.0'
module_blacklist:
# Deprecated
- docker
# We only allow pip, not easy_install
- easy_install

 

转载于:https://www.cnblogs.com/nineep/p/9081422.html

你可能感兴趣的:(ansible plugins简介)