Ansible 2.3 移植指南
本节讨论 Ansible 2.2 和 Ansible 2.3 之间的行为变化。
旨在帮助您更新您的剧本、插件以及 Ansible 基础架构的其他部分,以便它们能够与该版本的 Ansible 协同工作。
建议您阅读此页面以及 Ansible 2.3 的变更日志,以了解您可能需要进行哪些更新。
本文档是移植集合的一部分。完整的移植指南列表可在 移植指南 中找到。
剧本 (Playbook)
重构异步操作以与 action 插件协同工作
在 Ansible 2.2(以及可能更早的版本)中,async: 关键字不能与 action 插件(如 service)一起使用。此限制已在 Ansible 2.3 中移除。
**新增** Ansible 2.3 中
- name: Install nginx asynchronously
service:
name: nginx
state: restarted
async: 45
OpenBSD 版本信息
在 Ansible 2.2 及更早版本中,OpenBSD 主机上的 ansible_distribution_release 和 ansible_distribution_version 信息反转了。此问题已得到修正,版本信息包含数字部分,而发行版包含发行版的名称。
**旧版** Ansible 2.2(及更早版本)中
"ansible_distribution": "OpenBSD"
"ansible_distribution_release": "6.0",
"ansible_distribution_version": "release",
**新增** Ansible 2.3 中
"ansible_distribution": "OpenBSD",
"ansible_distribution_release": "release",
"ansible_distribution_version": "6.0",
命名块
块现在可以有名称,这允许您避免使用难看的 # this block is for… 注释。
**新增** Ansible 2.3 中
- name: Block test case
hosts: localhost
tasks:
- name: Attempt to setup foo
block:
- debug: msg='I execute normally'
- command: /bin/false
- debug: msg='I never execute, cause ERROR!'
rescue:
- debug: msg='I caught an error'
- command: /bin/false
- debug: msg='I also never execute :-('
always:
- debug: msg="this always executes"
其他注意事项
以下是更新时可能遇到的几种罕见情况。这些情况主要由更严格的解析器验证和对以前被忽略的错误的捕获引起。
使
any_errors_fatal
可从剧本继承到任务以及两者之间的所有其他对象。
模块 (Modules)
此版本中没有重大更改。
已移除的模块
此版本中没有重大更改。
弃用通知
以下模块将在 Ansible 2.5 中移除。请相应地更新您的剧本。
ec2_vpc
cl_bond
cl_bridge
cl_img_install
cl_interface
cl_interface_policy
cl_license
cl_ports
nxos_mtu 请使用 nxos_system 代替
注意
这些模块在当前版本中可能不再有文档。如果您需要了解它们的工作方式以移植您的剧本,请参阅 Ansible 2.3 模块文档。
值得注意的模块更改
AWS lambda
以前忽略的更改,这些更改仅影响一个参数。现有部署可能存在此错误修复程序将应用的未完成更改。
挂载 (Mount)
挂载:一些修复程序,以便不会每次运行剧本时都挂载绑定挂载。
插件 (Plugins)
此版本中没有重大更改。
移植自定义脚本
此版本中没有重大更改。
网络
网络模块的操作方式已发生许多更改。
剧本仍应使用 connection: local
。
以下更改适用于
dellos6
dellos9
dellos10
eos
ios
iosxr
junos
sros
vyos
顶级连接参数的弃用
**旧版** Ansible 2.2 中
- name: example of using top-level options for connection properties
ios_command:
commands: show version
host: "{{ inventory_hostname }}"
username: cisco
password: cisco
authorize: yes
auth_pass: cisco
将导致
[WARNING]: argument username has been deprecated and will be removed in a future version
[WARNING]: argument host has been deprecated and will be removed in a future version
[WARNING]: argument password has been deprecated and will be removed in a future version
**新增** Ansible 2.3 中
- name: Gather facts
eos_facts:
gather_subset: all
provider:
username: myuser
password: "{{ networkpassword }}"
transport: cli
host: "{{ ansible_host }}"
ProxyCommand 替代 delegate_to
Ansible 2.3 中使用 cli
传输的网络模块的新连接框架不再支持使用 delegate_to
指令。为了使用堡垒机或中间跳转主机通过 cli
传输连接到网络设备,网络模块现在支持使用 ProxyCommand
。
要使用 ProxyCommand
,请在 Ansible 清单文件中配置代理设置,以通过 ansible_ssh_common_args
指定代理主机。
有关如何执行此操作的详细信息,请参阅 网络代理指南。