Issue 1:
From @juju4 on November 11, 2016 23:34

ISSUE TYPE

Bug Report

COMPONENT NAME

hostname module

ANSIBLE VERSION

# ansible --version
ansible 2.2.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

OS / ENVIRONMENT

local run on ubuntu xenial (inside lxc containers with kitchen-test+kitchen-ansible)

SUMMARY

hostname module fails to set with above error

STEPS TO REPRODUCE

- debug: var=hostname_hostname
- name: set hostname
hostname: "name={{ hostname_hostname }}"

EXPECTED RESULTS

set hostname without error.

was working with ansible 2.1

ACTUAL RESULTS

task is failing

TASK [hostname : debug] ********************************************************
task path: /tmp/kitchen/hostname/tasks/main.yml:3
ok: [localhost] => {
"hostname_hostname": "example"
}

TASK [hostname : set hostname] *************************************************
task path: /tmp/kitchen/hostname/tasks/main.yml:4
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/core/system/hostname.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: root
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250 `" && echo ansible-tmp-1478906878.17-90221180289250="` echo $HOME/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250 `" ) && sleep 0'
<localhost> PUT /tmp/tmpDdbhyS TO /root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/hostname.py
<localhost> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/ /root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/hostname.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/hostname.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/" > /dev/null 2>&1 && sleep 0'
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"name": "example"
},
"module_name": "hostname"
},
"msg": "Command failed rc=1, out=, err=Could not set property: Failed to activate service 'org.freedesktop.hostname1': timed out\n"
}
to retry, use: --limit @/tmp/kitchen/default.retry

PLAY RECAP *********************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=1

trying

systemctl restart systemd-logind

and restarting playbook doesn't help

using hostname command directly is working.

Copied from original issue: ansible/ansible-modules-core#5582

Issue 2:
From @xrow on October 22, 2015 8:12

Hi,

I prepared a usecase that will fail with ansible https://github.com/xrow/docker.ansible.bug1. The output will be like this.

I believe the reason why hostnamectl doesn't exists is that the systemd package was replaced by systemd-container. Maybe the solution would be to skip that task if the binary doesn't exist.

ISSUE TYPE

Bug Report

COMPONENT NAME

hostname

ANSIBLE VERSION

any

-bash-4.2# docker build -f Dockerfile -t bash .
Sending build context to Docker daemon 7.68 kB
Sending build context to Docker daemon
Step 0 : FROM centos:7
---> ce20c473cd8a
Step 1 : MAINTAINER "BjÃ¶rn Dieding" <bjoern@xrow.de>
---> Using cache
---> d3eec8a3bf48
Step 2 : VOLUME /run /tmp /sys/fs/cgroup
---> Using cache
---> bb410b68dadb
Step 3 : ADD RPM-GPG-KEY-EPEL-7 /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
---> Using cache
---> ac7e3e116967
Step 4 : ADD epel.repo /etc/yum.repos.d/epel.repo
---> Using cache
---> de7ff6cb9763
Step 5 : RUN yum install -y ansible
---> Using cache
---> 32686ff89319
Step 6 : RUN yum -y install python-pip redis
---> Using cache
---> 4bbd888b3814
Step 7 : RUN pip install redis
---> Using cache
---> b1b1aad0c28e
Step 8 : ADD test.yml test.yml
---> Using cache
---> 76747563e5da
Step 9 : RUN echo "[ezcluster]" > /etc/ansible/hosts
---> Using cache
---> b5c1c7fa2430
Step 10 : RUN echo "localhost" >> /etc/ansible/hosts
---> Using cache
---> a0916c3c8ee2
Step 11 : RUN ansible-playbook -c local test.yml -vvvv
---> Running in 338a9e2b6ec4

PLAY [ezcluster] **************************************************************

GATHERING FACTS ***************************************************************
<localhost> REMOTE_MODULE setup
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399 && echo $HOME/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399']
<localhost> PUT /tmp/tmpoBWhBT TO /root/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399/setup
<localhost> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399/ >/dev/null 2>&1']
ok: [localhost]

TASK: [hostname name=myhostname] **********************************************
<localhost> REMOTE_MODULE hostname name=myhostname
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714 && echo $HOME/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714']
<localhost> PUT /tmp/tmpNbuHLK TO /root/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714/hostname
<localhost> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714/hostname; rm -rf /root/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714/ >/dev/null 2>&1']
failed: [localhost] => {"cmd": "hostnamectl --transient set-hostname myhostname", "failed": true, "rc": 2}
msg: [Errno 2] No such file or directory

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
to retry, use: --limit @/root/test.retry

localhost : ok=1 changed=0 unreachable=0 failed=1

The command '/bin/sh -c ansible-playbook -c local test.yml -vvvv' returned a non-zero code: 2

Copied from original issue: ansible/ansible-modules-core#2331