Repository: ansible/ansible

Issue:
dnf autoremove parameter default not documented
##### ISSUE TYPE
 - Documentation Report

##### COMPONENT NAME
https://docs.ansible.com/ansible/latest/modules/dnf_module.html

##### ANSIBLE VERSION
```
ansible 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Mar 14 2018, 16:45:33) [GCC 8.0.1 20180222 (Red Hat 8.0.1-0.16)]
```

##### SUMMARY
The dnf module parameter autoremove has no default value documented at https://docs.ansible.com/ansible/latest/modules/dnf_module.html.


Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
@myllynen Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- ansible version

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
Urgh.. Trying to make the bot happy:

##### ANSIBLE VERSION
```
ansible 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Mar 14 2018, 16:45:33) [GCC 8.0.1 20180222 (Red Hat 8.0.1-0.16)]
```

Resolving patch:
diff --git a/lib/ansible/modules/packaging/os/dnf.py b/lib/ansible/modules/packaging/os/dnf.py
--- a/lib/ansible/modules/packaging/os/dnf.py
+++ b/lib/ansible/modules/packaging/os/dnf.py
@@ -29,6 +29,8 @@
         When using state=latest, this can be '*' which means run: dnf -y update.
         You can also pass a url or a local path to a rpm file."
     required: true
+    aliases:
+        - pkg
 
   list:
     description:
@@ -37,7 +39,7 @@
   state:
     description:
       - Whether to install (C(present), C(latest)), or remove (C(absent)) a package.
-    choices: [ "present", "latest", "absent" ]
+    choices: ['absent', 'present', 'installed', 'removed', 'latest']
     default: "present"
 
   enablerepo:
@@ -84,6 +86,7 @@
         installed as dependencies of user-installed packages but which are no longer
         required by any such package. Should be used alone or when state is I(absent)
     type: bool
+    default: false
     version_added: "2.4"
 notes:
   - When used with a `loop:` each package will be processed individually, it is much more efficient to pass the list directly to the `name` option.
@@ -326,7 +329,7 @@ def ensure(module, base, state, names, autoremove):
 
     # Autoremove is called alone
     # Jump to remove path where base.autoremove() is run
-    if not names and autoremove is not None:
+    if not names and autoremove:
         names = []
         state = 'absent'
 
@@ -412,7 +415,7 @@ def ensure(module, base, state, names, autoremove):
 
         else:
             # state == absent
-            if autoremove is not None:
+            if autoremove:
                 base.conf.clean_requirements_on_remove = autoremove
 
             if filenames:
@@ -480,15 +483,16 @@ def main():
         argument_spec=dict(
             name=dict(aliases=['pkg'], type='list'),
             state=dict(
-                choices=[
-                    'absent', 'present', 'installed', 'removed', 'latest']),
+                choices=['absent', 'present', 'installed', 'removed', 'latest'],
+                default='present',
+            ),
             enablerepo=dict(type='list', default=[]),
             disablerepo=dict(type='list', default=[]),
             list=dict(),
             conf_file=dict(default=None, type='path'),
             disable_gpg_check=dict(default=False, type='bool'),
             installroot=dict(default='/', type='path'),
-            autoremove=dict(type='bool'),
+            autoremove=dict(type='bool', default=False),
             releasever=dict(default=None),
         ),
         required_one_of=[['name', 'list', 'autoremove']],
@@ -499,7 +503,7 @@ def main():
     _ensure_dnf(module)
 
     # Check if autoremove is called correctly
-    if params['autoremove'] is not None:
+    if params['autoremove']:
         if LooseVersion(dnf.__version__) < LooseVersion('2.0.1'):
             module.fail_json(msg="Autoremove requires dnf>=2.0.1. Current dnf version is %s" % dnf.__version__)
         if params['state'] not in ["absent", None]:


Test patch:
diff --git a/test/sanity/validate-modules/ignore.txt b/test/sanity/validate-modules/ignore.txt
--- a/test/sanity/validate-modules/ignore.txt
+++ b/test/sanity/validate-modules/ignore.txt
@@ -1037,9 +1037,6 @@ lib/ansible/modules/packaging/os/apt_repository.py E325
 lib/ansible/modules/packaging/os/apt_rpm.py E322
 lib/ansible/modules/packaging/os/apt_rpm.py E324
 lib/ansible/modules/packaging/os/apt_rpm.py E326
-lib/ansible/modules/packaging/os/dnf.py E322
-lib/ansible/modules/packaging/os/dnf.py E324
-lib/ansible/modules/packaging/os/dnf.py E326
 lib/ansible/modules/packaging/os/homebrew.py E326
 lib/ansible/modules/packaging/os/homebrew_cask.py E326
 lib/ansible/modules/packaging/os/layman.py E322