在 Linux 主机上运行的脚本应该调用一些持有 Oracle 数据库的 Windows 主机。每个 Oracle 数据库都在 DNS 中,名称为“db-[ORACLE_SID]”。
假设您有一个 ORACLE SID TEST02
的数据库,它可以解析为 db-TEST02
。
完整的脚本做了一些更多的事情,但这个例子足以说明问题。
db-[SID]
主机名必须添加为动态主机才能并行处理。
问题是 oracle_databases 没有传递给新的剧本。如果我将主机从 windows
更改为 localhost
,它会起作用,但是我需要先分析一些东西并从 windows 主机获取一些数据,所以这不是一个选项。
脚本如下:
---
# ansible-playbook parallel.yml -e "databases=TEST01,TEST02,TEST03"
- hosts: windows
gather_facts: false
vars:
ansible_connection: winrm
ansible_port: 5985
ansible_winrm_transport: kerberos
ansible_winrm_kerberos_delegation: true
tasks:
- set_fact:
database: "{{ databases.split(',') }}"
- name: Add databases as hosts, to parallelize the shutdown process
add_host:
name: "db-{{ item }}"
groups: oracle_databases
loop: "{{ database | list}}"
##### just to check, what is in oracle_databases
- name: show the content of oracle_databases
debug:
msg: "{{ item }}"
with_inventory_hostnames:
- oracle_databases
- hosts: oracle_databases
gather_facts: true
tasks:
- debug:
msg:
- "Hosts, on which the playbook is running: {{ ansible_play_hosts }}"
verbosity: 1
我的清单文件很小,但将来会有更多的 Windows 主机:
[adminsw1@obelix oracle_change_home]$ cat inventory
[local]
localhost
[windows]
windows68
和输出
[adminsw1@obelix oracle_change_home]$ ansible-playbook para.yml -l windows68 -e "databases=TEST01,TEST02"
/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
/usr/lib/python2.7/site-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.23) or chardet (2.2.1) doesn't match a supported version!
RequestsDependencyWarning)
PLAY [windows] *****************************************************************************************************************************
TASK [set_fact] ****************************************************************************************************************************
ok: [windows68]
TASK [Add databases as hosts, to parallelize the shutdown process] *************************************************************************
changed: [windows68] => (item=TEST01)
changed: [windows68] => (item=TEST02)
TASK [show the content of oracle_databases] ************************************************************************************************
ok: [windows68] => (item=db-TEST01) => {
"msg": "db-TEST01"
}
ok: [windows68] => (item=db-TEST02) => {
"msg": "db-TEST02"
}
PLAY [oracle_databases] ********************************************************************************************************************
skipping: no hosts matched
PLAY RECAP *********************************************************************************************************************************
windows68 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
答案 0 :(得分:0)
Ansible 可能没有解析更新的清单文件,或者在更新清单时主机名格式不正确。
在这种情况下,您可以在 Ansible 命令中使用 -vv 或 -vvvv 参数来获取额外的日志记录。
这将使您全面了解 Ansible 在尝试解析主机时实际在做什么。
答案 1 :(得分:0)
我发现了,问题出在哪里。该剧本仅限于主机“windows68”,因此无法在动态清单添加的主机上运行。 它将以这种方式工作:
[adminsw1@obelix oracle_change_home]$ ansible-playbook para.yml -l windows68,oracle_databases -e "databases=TEST01,TEST02"