Repository: ansible/ansible

Issue:
tower_inventory module cannot create smart inventories
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
The tower_inventory module cannot create Smart Inventories in Tower.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path-->

tower_inventory

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.4
  config file = None
  configured module search path = [u'/Users/evanjame/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.5.4/libexec/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.15 (default, May  1 2018, 16:44:37) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).-->

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.-->
N/A 
AWX 1.0.6.8

##### STEPS TO REPRODUCE
<!--- For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used. -->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
- name: Add Smart Foreman inventory
  tower_inventory:
    name: "Library Inventory"
    description: "All Foreman Hosts in the Library environment"
    organization: "Bar Org"
    kind: smart
    host_filter: groups__name=foreman_lifecycle_environment_Library
    state: present
    tower_config_file: "~/tower_cli.cfg"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Creates new Smart Inventory named "Library Inventory" with hosts from the Library lifecycle environment. 
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (tower_inventory) module: host_filter, kind Supported parameters include: description, name, organization, state, tower_config_file, tower_host, tower_********, tower_username, tower_verify_ssl, variables"}
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py
--- a/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py
+++ b/lib/ansible/modules/web_infrastructure/ansible_tower/tower_inventory.py
@@ -37,6 +37,16 @@
     variables:
       description:
         - Inventory variables. Use C(@) to get from file.
+    kind:
+      description:
+        - The kind field. Cannot be modified after created.
+      default: ""
+      choices: ["", "smart"]
+      version_added: "2.7"
+    host_filter:
+      description:
+        -  The host_filter field. Only useful when C(kind=smart).
+      version_added: "2.7"
     state:
       description:
         - Desired state of the resource.
@@ -75,6 +85,8 @@ def main():
         description=dict(),
         organization=dict(required=True),
         variables=dict(),
+        kind=dict(choices=['', 'smart'], default=''),
+        host_filter=dict(),
         state=dict(choices=['present', 'absent'], default='present'),
     ))
 
@@ -88,6 +100,8 @@ def main():
     organization = module.params.get('organization')
     variables = module.params.get('variables')
     state = module.params.get('state')
+    kind = module.params.get('kind')
+    host_filter = module.params.get('host_filter')
 
     json_output = {'inventory': name, 'state': state}
 
@@ -102,7 +116,8 @@ def main():
 
             if state == 'present':
                 result = inventory.modify(name=name, organization=org['id'], variables=variables,
-                                          description=description, create_on_missing=True)
+                                          description=description, kind=kind, host_filter=host_filter,
+                                          create_on_missing=True)
                 json_output['id'] = result['id']
             elif state == 'absent':
                 result = inventory.delete(name=name, organization=org['id'])


Test patch: