<p dir="auto"><em>From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/juju4/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/juju4">@juju4</a> on November 11, 2016 23:34</em></p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">hostname module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# ansible --version
ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate"># ansible --version
ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">local run on ubuntu xenial (inside lxc containers with kitchen-test+kitchen-ansible)</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">hostname module fails to set with above error</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- debug: var=hostname_hostname
- name: set hostname
  hostname: &quot;name={{ hostname_hostname }}&quot;"><pre class="notranslate"><code class="notranslate">- debug: var=hostname_hostname
- name: set hostname
  hostname: "name={{ hostname_hostname }}"
</code></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">set hostname without error.<br>
was working with ansible 2.1</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">task is failing</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TASK [hostname : debug] ********************************************************
task path: /tmp/kitchen/hostname/tasks/main.yml:3
ok: [localhost] =&gt; {
    &quot;hostname_hostname&quot;: &quot;example&quot;
}

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
&lt;localhost&gt; ESTABLISH LOCAL CONNECTION FOR USER: root
&lt;localhost&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250 `&quot; &amp;&amp; echo ansible-tmp-1478906878.17-90221180289250=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250 `&quot; ) &amp;&amp; sleep 0'
&lt;localhost&gt; PUT /tmp/tmpDdbhyS TO /root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/hostname.py
&lt;localhost&gt; 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 &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/hostname.py; rm -rf &quot;/root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/&quot; &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'
fatal: [localhost]: FAILED! =&gt; {
    &quot;changed&quot;: false, 
    &quot;failed&quot;: true, 
    &quot;invocation&quot;: {
        &quot;module_args&quot;: {
            &quot;name&quot;: &quot;example&quot;
        }, 
        &quot;module_name&quot;: &quot;hostname&quot;
    }, 
    &quot;msg&quot;: &quot;Command failed rc=1, out=, err=Could not set property: Failed to activate service 'org.freedesktop.hostname1': timed out\n&quot;
}
        to retry, use: --limit @/tmp/kitchen/default.retry

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=1 "><pre class="notranslate"><code class="notranslate">TASK [hostname : debug] ********************************************************
task path: /tmp/kitchen/hostname/tasks/main.yml:3
ok: [localhost] =&gt; {
    "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
&lt;localhost&gt; ESTABLISH LOCAL CONNECTION FOR USER: root
&lt;localhost&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250 `" &amp;&amp; echo ansible-tmp-1478906878.17-90221180289250="` echo $HOME/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250 `" ) &amp;&amp; sleep 0'
&lt;localhost&gt; PUT /tmp/tmpDdbhyS TO /root/.ansible/tmp/ansible-tmp-1478906878.17-90221180289250/hostname.py
&lt;localhost&gt; 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 &amp;&amp; sleep 0'
&lt;localhost&gt; 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/" &gt; /dev/null 2&gt;&amp;1 &amp;&amp; sleep 0'
fatal: [localhost]: FAILED! =&gt; {
    "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 
</code></pre></div>
<p dir="auto">trying</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="systemctl restart systemd-logind"><pre class="notranslate"><code class="notranslate">systemctl restart systemd-logind
</code></pre></div>
<p dir="auto">and restarting playbook doesn't help</p>
<p dir="auto">using hostname command directly is working.</p>
<p dir="auto"><em>Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="188873668" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/5582" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/5582/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/5582">ansible/ansible-modules-core#5582</a></em></p>
<p dir="auto"><em>From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/xrow/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/xrow">@xrow</a> on October 22, 2015 8:12</em></p>
<p dir="auto">Hi,</p>
<p dir="auto">I prepared a usecase that will fail with ansible <a href="https://github.com/xrow/docker.ansible.bug1">https://github.com/xrow/docker.ansible.bug1</a>. The output will be like this.</p>
<p dir="auto">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.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">hostname</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">any</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-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
 ---&gt; ce20c473cd8a
Step 1 : MAINTAINER &quot;BjÃ¶rn Dieding&quot; &lt;bjoern@xrow.de&gt;
 ---&gt; Using cache
 ---&gt; d3eec8a3bf48
Step 2 : VOLUME /run /tmp /sys/fs/cgroup
 ---&gt; Using cache
 ---&gt; bb410b68dadb
Step 3 : ADD RPM-GPG-KEY-EPEL-7 /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 ---&gt; Using cache
 ---&gt; ac7e3e116967
Step 4 : ADD epel.repo /etc/yum.repos.d/epel.repo
 ---&gt; Using cache
 ---&gt; de7ff6cb9763
Step 5 : RUN yum install -y ansible
 ---&gt; Using cache
 ---&gt; 32686ff89319
Step 6 : RUN yum -y install python-pip redis
 ---&gt; Using cache
 ---&gt; 4bbd888b3814
Step 7 : RUN pip install redis
 ---&gt; Using cache
 ---&gt; b1b1aad0c28e
Step 8 : ADD test.yml test.yml
 ---&gt; Using cache
 ---&gt; 76747563e5da
Step 9 : RUN echo &quot;[ezcluster]&quot; &gt; /etc/ansible/hosts
 ---&gt; Using cache
 ---&gt; b5c1c7fa2430
Step 10 : RUN echo &quot;localhost&quot; &gt;&gt; /etc/ansible/hosts
 ---&gt; Using cache
 ---&gt; a0916c3c8ee2
Step 11 : RUN ansible-playbook -c local test.yml -vvvv
 ---&gt; Running in 338a9e2b6ec4

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

GATHERING FACTS *************************************************************** 
&lt;localhost&gt; REMOTE_MODULE setup
&lt;localhost&gt; EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399']
&lt;localhost&gt; PUT /tmp/tmpoBWhBT TO /root/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399/setup
&lt;localhost&gt; 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/ &gt;/dev/null 2&gt;&amp;1']
ok: [localhost]

TASK: [hostname name=myhostname] ********************************************** 
&lt;localhost&gt; REMOTE_MODULE hostname name=myhostname
&lt;localhost&gt; EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714']
&lt;localhost&gt; PUT /tmp/tmpNbuHLK TO /root/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714/hostname
&lt;localhost&gt; 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/ &gt;/dev/null 2&gt;&amp;1']
failed: [localhost] =&gt; {&quot;cmd&quot;: &quot;hostnamectl --transient set-hostname myhostname&quot;, &quot;failed&quot;: true, &quot;rc&quot;: 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"><pre class="notranslate"><code class="notranslate">-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
 ---&gt; ce20c473cd8a
Step 1 : MAINTAINER "BjÃ¶rn Dieding" &lt;bjoern@xrow.de&gt;
 ---&gt; Using cache
 ---&gt; d3eec8a3bf48
Step 2 : VOLUME /run /tmp /sys/fs/cgroup
 ---&gt; Using cache
 ---&gt; bb410b68dadb
Step 3 : ADD RPM-GPG-KEY-EPEL-7 /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 ---&gt; Using cache
 ---&gt; ac7e3e116967
Step 4 : ADD epel.repo /etc/yum.repos.d/epel.repo
 ---&gt; Using cache
 ---&gt; de7ff6cb9763
Step 5 : RUN yum install -y ansible
 ---&gt; Using cache
 ---&gt; 32686ff89319
Step 6 : RUN yum -y install python-pip redis
 ---&gt; Using cache
 ---&gt; 4bbd888b3814
Step 7 : RUN pip install redis
 ---&gt; Using cache
 ---&gt; b1b1aad0c28e
Step 8 : ADD test.yml test.yml
 ---&gt; Using cache
 ---&gt; 76747563e5da
Step 9 : RUN echo "[ezcluster]" &gt; /etc/ansible/hosts
 ---&gt; Using cache
 ---&gt; b5c1c7fa2430
Step 10 : RUN echo "localhost" &gt;&gt; /etc/ansible/hosts
 ---&gt; Using cache
 ---&gt; a0916c3c8ee2
Step 11 : RUN ansible-playbook -c local test.yml -vvvv
 ---&gt; Running in 338a9e2b6ec4

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

GATHERING FACTS *************************************************************** 
&lt;localhost&gt; REMOTE_MODULE setup
&lt;localhost&gt; EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399']
&lt;localhost&gt; PUT /tmp/tmpoBWhBT TO /root/.ansible/tmp/ansible-tmp-1445501553.12-214209363520399/setup
&lt;localhost&gt; 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/ &gt;/dev/null 2&gt;&amp;1']
ok: [localhost]

TASK: [hostname name=myhostname] ********************************************** 
&lt;localhost&gt; REMOTE_MODULE hostname name=myhostname
&lt;localhost&gt; EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714 &amp;&amp; echo $HOME/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714']
&lt;localhost&gt; PUT /tmp/tmpNbuHLK TO /root/.ansible/tmp/ansible-tmp-1445501554.51-46884008533714/hostname
&lt;localhost&gt; 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/ &gt;/dev/null 2&gt;&amp;1']
failed: [localhost] =&gt; {"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
</code></pre></div>
<p dir="auto"><em>Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="112751612" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/2331" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/2331/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/2331">ansible/ansible-modules-core#2331</a></em></p>