Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the hostname command is not installed, hostname is failed. #74556

Closed
1 task done
rearn opened this issue May 4, 2021 · 12 comments
Closed
1 task done

If the hostname command is not installed, hostname is failed. #74556

rearn opened this issue May 4, 2021 · 12 comments
Assignees
Labels
affects_2.12 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@rearn
Copy link

rearn commented May 4, 2021

Summary

If the hostname command is not installed, hostname is failed. (e.g. archlinux )

I think the problem is that it is hard-coded in the following section.
https://github.com/ansible/ansible/blob/v2.11.0/lib/ansible/modules/hostname.py#L187

Issue Type

Bug Report

Component Name

hostname.py

Ansible Version

$ ansible --version
ansible [core 2.11.0] 
  config file = /vagrant/ansible/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.4 (default, Apr 20 2021, 15:51:38) [GCC 10.2.0]
  jinja version = 2.11.3
  libyaml = True

Configuration

$ ansible-config dump --only-changed
DEFAULT_ROLES_PATH(/vagrant/ansible/ansible.cfg) = ['/vagrant/roles', '/vagrant/ansible/roles']
DEFAULT_VAULT_PASSWORD_FILE(/vagrant/ansible/ansible.cfg) = /vagrant/ansible/.vault_passwd
INTERPRETER_PYTHON(/vagrant/ansible/ansible.cfg) = auto

OS / Environment

Archlinux

Steps to Reproduce

- hosts: localhost
  tasks:
    - name: set hostname
      hostname:
        name: example.com

Expected Results

Expected hostname to change

Actual Results

$ ansible-playbook test.yml -vvvv
ansible-playbook [core 2.11.0] 
  config file = /vagrant/ansible/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.4 (default, Apr 20 2021, 15:51:38) [GCC 10.2.0]
  jinja version = 2.11.3
  libyaml = True
Using /vagrant/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /vagrant/ansible/inventry_vagrant as it did not pass its verify_file() method
script declined parsing /vagrant/ansible/inventry_vagrant as it did not pass its verify_file() method
auto declined parsing /vagrant/ansible/inventry_vagrant as it did not pass its verify_file() method
Parsed /vagrant/ansible/inventry_vagrant inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: gw copy.yml ***********************************************************************************************************************************************************************************************************
Positional arguments: playbooks/gw copy.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/vagrant/ansible/inventry_vagrant',)
forks: 5
1 plays in playbooks/gw copy.yml

PLAY [localhost] ****************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************
task path: /vagrant/ansible/playbooks/gw copy.yml:1
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible-$USER `"&& mkdir "` echo /tmp/ansible-$USER/ansible-tmp-1620107817.357103-6570-83621929588651 `" && echo ansible-tmp-1620107817.357103-6570-83621929588651="` echo /tmp/ansible-$USER/ansible-tmp-1620107817.357103-6570-83621929588651 `" ) && sleep 0'
Using module file /usr/lib/python3.9/site-packages/ansible/modules/setup.py
<127.0.0.1> PUT /home/vagrant/.ansible/tmp/ansible-local-65668a5_gxm4/tmpb08x5v2_ TO /tmp/ansible-vagrant/ansible-tmp-1620107817.357103-6570-83621929588651/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/ansible-vagrant/ansible-tmp-1620107817.357103-6570-83621929588651/ /tmp/ansible-vagrant/ansible-tmp-1620107817.357103-6570-83621929588651/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /tmp/ansible-vagrant/ansible-tmp-1620107817.357103-6570-83621929588651/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/ansible-vagrant/ansible-tmp-1620107817.357103-6570-83621929588651/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [set hostname] *************************************************************************************************************************************************************************************************************
task path: /vagrant/ansible/playbooks/gw copy.yml:3
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible-$USER `"&& mkdir "` echo /tmp/ansible-$USER/ansible-tmp-1620107817.8607519-6606-77576043709009 `" && echo ansible-tmp-1620107817.8607519-6606-77576043709009="` echo /tmp/ansible-$USER/ansible-tmp-1620107817.8607519-6606-77576043709009 `" ) && sleep 0'
Using module file /usr/lib/python3.9/site-packages/ansible/modules/hostname.py
<127.0.0.1> PUT /home/vagrant/.ansible/tmp/ansible-local-65668a5_gxm4/tmpk2uy2rlb TO /tmp/ansible-vagrant/ansible-tmp-1620107817.8607519-6606-77576043709009/AnsiballZ_hostname.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/ansible-vagrant/ansible-tmp-1620107817.8607519-6606-77576043709009/ /tmp/ansible-vagrant/ansible-tmp-1620107817.8607519-6606-77576043709009/AnsiballZ_hostname.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /tmp/ansible-vagrant/ansible-tmp-1620107817.8607519-6606-77576043709009/AnsiballZ_hostname.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/ansible-vagrant/ansible-tmp-1620107817.8607519-6606-77576043709009/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_hostname_payload_rqp8suwp/ansible_hostname_payload.zip/ansible/module_utils/basic.py", line 1418, in get_bin_path
    bin_path = get_bin_path(arg=arg, opt_dirs=opt_dirs)
  File "/tmp/ansible_hostname_payload_rqp8suwp/ansible_hostname_payload.zip/ansible/module_utils/common/process.py", line 42, in get_bin_path
    raise ValueError('Failed to find required executable %s in paths: %s' % (arg, os.pathsep.join(paths)))
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "name": "example.com",
            "use": null
        }
    },
    "msg": "Failed to find required executable hostname in paths: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/sbin:/usr/sbin"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented May 4, 2021

Files identified in the description:

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

click here for bot help

@ansibot ansibot added affects_2.12 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels May 4, 2021
@mkrizek
Copy link
Contributor

mkrizek commented May 4, 2021

It is explicitly mentioned in the documentation that hostname is needed to execute this module:
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/hostname_module.html#requirements. The error message from the output you provided says it as well.

@rearn
Copy link
Author

rearn commented May 4, 2021

You're right.
However, in the case of systemd, hostname_cmd is rewritten with the hostnamectl command. [1]
So I think it is maked to run without hostname command.

[1] https://github.com/ansible/ansible/blob/v2.11.0/lib/ansible/modules/hostname.py#L406

@mkrizek
Copy link
Contributor

mkrizek commented May 4, 2021

Have you tried specifying the Systemd strategy as documented in https://docs.ansible.com/ansible/latest/collections/ansible/builtin/hostname_module.html#parameter-use?

- hostname:
    name: my_hostname
    use: systemd

@rearn
Copy link
Author

rearn commented May 4, 2021

The same is true if you run it with use: systemd.

- hosts: localhost
  tasks:
    - name: set hostname
      hostname:
        name: example.com
        use: systemd
$ ansible-playbook test.yml -vvvv
ansible-playbook [core 2.11.0] 
  config file = /vagrant/ansible/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.4 (default, Apr 20 2021, 15:51:38) [GCC 10.2.0]
  jinja version = 2.11.3
  libyaml = True
Using /vagrant/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3.9/site-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: test.yml **************************************************************************************************************************************************************************************************************
Positional arguments: test.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in test.yml

PLAY [localhost] ****************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************
task path: /vagrant/ansible/test.yml:1
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible-$USER `"&& mkdir "` echo /tmp/ansible-$USER/ansible-tmp-1620112642.8765-7050-46838698846273 `" && echo ansible-tmp-1620112642.8765-7050-46838698846273="` echo /tmp/ansible-$USER/ansible-tmp-1620112642.8765-7050-46838698846273 `" ) && sleep 0'
Using module file /usr/lib/python3.9/site-packages/ansible/modules/setup.py
<127.0.0.1> PUT /home/vagrant/.ansible/tmp/ansible-local-70467nd1xyjp/tmp89auxpyg TO /tmp/ansible-vagrant/ansible-tmp-1620112642.8765-7050-46838698846273/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/ansible-vagrant/ansible-tmp-1620112642.8765-7050-46838698846273/ /tmp/ansible-vagrant/ansible-tmp-1620112642.8765-7050-46838698846273/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /tmp/ansible-vagrant/ansible-tmp-1620112642.8765-7050-46838698846273/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/ansible-vagrant/ansible-tmp-1620112642.8765-7050-46838698846273/ > /dev/null 2>&1 && sleep 0'
ok: [localhost]
META: ran handlers

TASK [set hostname] *************************************************************************************************************************************************************************************************************
task path: /vagrant/ansible/test.yml:3
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: vagrant
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible-$USER `"&& mkdir "` echo /tmp/ansible-$USER/ansible-tmp-1620112643.3797443-7086-67775070687447 `" && echo ansible-tmp-1620112643.3797443-7086-67775070687447="` echo /tmp/ansible-$USER/ansible-tmp-1620112643.3797443-7086-67775070687447 `" ) && sleep 0'
Using module file /usr/lib/python3.9/site-packages/ansible/modules/hostname.py
<127.0.0.1> PUT /home/vagrant/.ansible/tmp/ansible-local-70467nd1xyjp/tmp9g_rhpat TO /tmp/ansible-vagrant/ansible-tmp-1620112643.3797443-7086-67775070687447/AnsiballZ_hostname.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /tmp/ansible-vagrant/ansible-tmp-1620112643.3797443-7086-67775070687447/ /tmp/ansible-vagrant/ansible-tmp-1620112643.3797443-7086-67775070687447/AnsiballZ_hostname.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /tmp/ansible-vagrant/ansible-tmp-1620112643.3797443-7086-67775070687447/AnsiballZ_hostname.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /tmp/ansible-vagrant/ansible-tmp-1620112643.3797443-7086-67775070687447/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_hostname_payload_nxcphvtr/ansible_hostname_payload.zip/ansible/module_utils/basic.py", line 1418, in get_bin_path
    bin_path = get_bin_path(arg=arg, opt_dirs=opt_dirs)
  File "/tmp/ansible_hostname_payload_nxcphvtr/ansible_hostname_payload.zip/ansible/module_utils/common/process.py", line 42, in get_bin_path
    raise ValueError('Failed to find required executable %s in paths: %s' % (arg, os.pathsep.join(paths)))
fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "name": "example.com",
            "use": "systemd"
        }
    },
    "msg": "Failed to find required executable hostname in paths: /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/sbin:/usr/sbin"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

@samdoran samdoran changed the title If the hostname command is not installed, ansible.built-in.hostname is failed. If the hostname command is not installed, hostname is failed. May 4, 2021
@samdoran samdoran added P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels May 4, 2021
@eqrx eqrx self-assigned this May 12, 2021
@lahwaacz
Copy link

Seems to be broken since #70532 which moved the systemd logic and made hostname always required.

@Akasurde
Copy link
Member

@rearn Could you please check if PR #74744 works for you and let us know? Thanks.

needs_info

@Akasurde
Copy link
Member

Akasurde commented May 20, 2021

resolved_by_pr #74744
resolved_by_pr #74797

@ansibot ansibot added has_pr This issue has an associated PR. needs_info This issue requires further information. Please answer any outstanding questions. labels May 20, 2021
@wookietreiber
Copy link
Contributor

FYI This issue was reported earlier (#67661) and was supposed to be solved (#67721). It seems there is no test to verify that this issue doesn't occur again.

@Akasurde
Copy link
Member

Akasurde commented Jun 7, 2021

@rearn @wookietreiber Could you please check if #74797 works for you and let us know? Thanks.

@rearn
Copy link
Author

rearn commented Jun 11, 2021

@Akasurde
I confirmed that it was working.
Thanks.

@Akasurde
Copy link
Member

@rearn Thanks for confirming this. I close this as resolved.

@ansible ansible locked and limited conversation to collaborators Jul 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.12 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants