| |
@@ -38,7 +38,7 @@
|
| |
parser = argparse.ArgumentParser(description="Inventory for local RPM installed host")
|
| |
parser.add_argument("--list", action="store_true", help="Verbose output")
|
| |
parser.add_argument('--host', help="Get host variables")
|
| |
- parser.add_argument("subjects", nargs="*", default=shlex.split(os.environ.get("TEST_SUBJECTS", "")))
|
| |
+ parser.add_argument("subjects", nargs="*", default=os.environ.get("TEST_SUBJECTS", ""))
|
| |
opts = parser.parse_args()
|
| |
|
| |
try:
|
| |
@@ -56,22 +56,13 @@
|
| |
|
| |
|
| |
def getlist(subjects):
|
| |
- repos = []
|
| |
- rpms = []
|
| |
hosts = []
|
| |
variables = {}
|
| |
|
| |
- for subject in subjects:
|
| |
- if subject.endswith(".rpm"):
|
| |
- rpms.append(subject)
|
| |
- elif isrepo(subject):
|
| |
- repos.append(subject)
|
| |
-
|
| |
- if repos or rpms:
|
| |
- host_vars = gethost(repos, rpms)
|
| |
- if host_vars:
|
| |
- hosts.append("rpms")
|
| |
- variables["rpms"] = vars
|
| |
+ host_vars = gethost(subjects)
|
| |
+ if host_vars:
|
| |
+ hosts.append("rpms")
|
| |
+ variables["rpms"] = host_vars
|
| |
|
| |
if not hosts:
|
| |
return EMPTY_INVENTORY
|
| |
@@ -80,7 +71,20 @@
|
| |
"_meta": {"hostvars": variables}}
|
| |
|
| |
|
| |
- def gethost(repos, rpms):
|
| |
+ def gethost(subjects):
|
| |
+ subjects = shlex.split(subjects)
|
| |
+ repos = []
|
| |
+ rpms = []
|
| |
+
|
| |
+ for subject in subjects:
|
| |
+ if subject.endswith(".rpm"):
|
| |
+ rpms.append(subject)
|
| |
+ elif isrepo(subject):
|
| |
+ repos.append(subject)
|
| |
+
|
| |
+ if not repos and not rpms:
|
| |
+ return EMPTY_INVENTORY
|
| |
+
|
| |
# The variables
|
| |
variables = {
|
| |
"ansible_connection": "local"
|
| |
Solve dynamic inventory output:
ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS=local ansible-inventory --list
[WARNING]: * Failed to parse /usr/share/ansible/inventory/standard-inventory-rpm with script plugin: Invalid data from file, expected dictionary and got: None
[WARNING]: * Failed to parse /usr/share/ansible/inventory/standard-inventory-rpm with yaml plugin: Syntax Error while loading YAML. mapping values are not allowed in this context The error appears to have
been in '/usr/share/ansible/inventory/standard-inventory-rpm': line 37, column 15, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: def main(argv):
^ here
[WARNING]: * Failed to parse /usr/share/ansible/inventory/standard-inventory-rpm with ini plugin: /usr/share/ansible/inventory/standard-inventory-rpm:27: Expected key=value host variable assignment, got:
argparse
[WARNING]: Unable to parse /usr/share/ansible/inventory/standard-inventory-rpm as an inventory source