Repository: ansible/ansible

Issue:
Cannot change hostname on Devuan OS
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
hostname

##### ANSIBLE VERSION
```
ansible 2.3.1.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

```

##### CONFIGURATION
N/A

##### OS / ENVIRONMENT
Ubuntu 16.04


##### SUMMARY
We can't use hostname module on [Devuan](https://devuan.org) (Debian fork).
##### STEPS TO REPRODUCE

```yaml
- name: HOSTNAME
  hostname: name={{ dbs_hostname }}
  notify: restart rsyslog
  register: change_hostname
```

##### EXPECTED RESULTS

Change hostname and no errors.

##### ACTUAL RESULTS
```
TASK [../../ : HOSTNAME] *******************************************************
task path: /home/XXXXXXXXXXX/ansible-debian-bootstrap/tasks/hostname.yml:6
fatal: [devuan-jessie]: FAILED! => {"changed": false, "failed": true, "msg": "hostname module cannot be used on platform Linux ()"}
	to retry, use: --limit @/home/XXXXXXXXXXX//ansible-debian-bootstrap/tests/test.retry
```



Discussion:
cc @alikins @saito-hideki
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
@HanXHX Thanks for reporting this issue. Can you provide output for following command - 

```
python -c "import platform; print(platform.linux_distribution())"
```
```
root@devuan:~{1}# python -c "import platform; print(platform.linux_distribution())"
('', '', '')
```

I give you more info about this OS:
```
root@devuan:~{0}# lsb_release -av
No LSB modules are available.
Distributor ID:	Devuan
Description:	Devuan GNU/Linux 1.0 (jessie)
Release:	1.0
Codename:	jessie
```
```
root@devuan:~{0}# cat /etc/os-release 
PRETTY_NAME="Devuan GNU/Linux 1 (jessie)"
NAME="Devuan GNU/Linux"
VERSION_ID="1"
VERSION="1 (jessie)"
ID=devuan
HOME_URL="http://www.devuan.org/"
SUPPORT_URL="http://www.devuan.org/support/"
BUG_REPORT_URL="https://bugs.devuan.org/"
```

@HanXHX Ansible rely on Python's platform to determine [Platform](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py#L264) value. I don't know how to proceed from here. @bcoca @jctanner Can you comment on this ?
@Akasurde Devuan provides an /etc/devuan_version file

I don't know side effects. But I think, you just need to patch (and add "devuan"): https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils/basic.py#L263

```
root@devuan:~{0}# cat /etc/devuan_version 
jessie
```

```
root@devuan:~{0}# python -c "import platform; supported_dists = platform._supported_dists + ('arch', 'alpine', 'devuan'); print(platform.linux_distribution(supported_dists=supported_dists))" 
('devuan', 'jessie', '')
```
Looks like @HanXHX has the solution, just need to fix detection to recognize Devuan as a 'non systemd' system.

Resolving patch:
diff --git a/lib/ansible/module_utils/basic.py b/lib/ansible/module_utils/basic.py
--- a/lib/ansible/module_utils/basic.py
+++ b/lib/ansible/module_utils/basic.py
@@ -260,7 +260,7 @@ def get_distribution():
     ''' return the distribution name '''
     if platform.system() == 'Linux':
         try:
-            supported_dists = platform._supported_dists + ('arch', 'alpine')
+            supported_dists = platform._supported_dists + ('arch', 'alpine', 'devuan')
             distribution = platform.linux_distribution(supported_dists=supported_dists)[0].capitalize()
             if not distribution and os.path.isfile('/etc/system-release'):
                 distribution = platform.linux_distribution(supported_dists=['system'])[0].capitalize()
diff --git a/lib/ansible/modules/system/hostname.py b/lib/ansible/modules/system/hostname.py
--- a/lib/ansible/modules/system/hostname.py
+++ b/lib/ansible/modules/system/hostname.py
@@ -707,6 +707,11 @@ class LinaroHostname(Hostname):
     distribution = 'Linaro'
     strategy_class = DebianStrategy
 
+class DevuanHostname(Hostname):
+    platform = 'Linux'
+    distribution = 'Devuan'
+    strategy_class = DebianStrategy
+
 class GentooHostname(Hostname):
     platform = 'Linux'
     distribution = 'Gentoo base system'


Test patch: