Как указано в https://docs.chef.io/resource_hostname.html doc hostname
, ресурс работает в "Новое в клиенте Chef 14.0.
Кроме того, после того, как он попробует, мне кажется, что он работает по крайней мере. См.следующие журналы:
vagrant@ubuntu-xenial:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.5 LTS"
vagrant@ubuntu-xenial:~$ hostname
ubuntu-xenial
vagrant@ubuntu-xenial:~$ curl -O https://packages.chef.io/files/stable/chef/14.5.33/ubuntu/18.04/chef_14.5.33-1_amd64.deb && sudo dpkg -i chef_14.5.33-1_amd64.deb
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 51.6M 100 51.6M 0 0 3431k 0 0:00:15 0:00:15 --:--:-- 3016k
Selecting previously unselected package chef.
(Reading database ... 54150 files and directories currently installed.)
Preparing to unpack chef_14.5.33-1_amd64.deb ...
Unpacking chef (14.5.33-1) ...
Setting up chef (14.5.33-1) ...
Thank you for installing Chef!
vagrant@ubuntu-xenial:~$ mkdir -p cookbooks/sethostname/recipes
vagrant@ubuntu-xenial:~$ vim cookbooks/sethostname/recipes/default.rb
vagrant@ubuntu-xenial:~$ echo "hostname 'example'" > cookbooks/sethostname/recipes/default.rb
vagrant@ubuntu-xenial:~$ cat cookbooks/sethostname/recipes/default.rb
hostname 'example'
vagrant@ubuntu-xenial:~$ sudo chef-client -z -o sethostname
[2018-10-22T04:31:22+00:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 14.5.33
[2018-10-22T04:31:24+00:00] WARN: Run List override has been provided.
[2018-10-22T04:31:24+00:00] WARN: Run List override has been provided.
[2018-10-22T04:31:24+00:00] WARN: Original Run List: []
[2018-10-22T04:31:24+00:00] WARN: Original Run List: []
[2018-10-22T04:31:24+00:00] WARN: Overridden Run List: [recipe[sethostname]]
[2018-10-22T04:31:24+00:00] WARN: Overridden Run List: [recipe[sethostname]]
resolving cookbooks for run list: ["sethostname"]
Synchronizing Cookbooks:
- sethostname (0.0.0)
Installing Cookbook Gems:
Compiling Cookbooks...
Recipe: sethostname::default
* hostname[example] action set
* ohai[reload hostname] action nothing (skipped due to action :nothing)
* execute[set hostname to example] action run
- execute /bin/hostname example
* file[/etc/hosts] action create
- update content in file /etc/hosts from 7ea6de to fb5e96
--- /etc/hosts 2018-10-22 04:27:39.004000000 +0000
+++ /etc/.chef-hosts20181022-1725-1ghvofd 2018-10-22 04:31:24.503686000 +0000
@@ -8,5 +8,5 @@
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
127.0.1.1 ubuntu-xenial ubuntu-xenial
-
+10.0.2.15 example example
* execute[hostnamectl set-hostname example] action run
- execute hostnamectl set-hostname example
* ohai[reload hostname] action reload/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.5.4/lib/ohai/plugins/windows/filesystem.rb:26: warning: already initialized constant CONVERSION_STATUS
/opt/chef/embedded/lib/ruby/gems/2.5.0/gems/ohai-14.5.4/lib/ohai/plugins/windows/filesystem.rb:26: warning: previous definition of CONVERSION_STATUS was here
- re-run ohai and merge results into node attributes
Converging 1 resources
* hostname[example] action set
* ohai[reload hostname] action nothing (skipped due to action :nothing)
* execute[set hostname to example] action run (skipped due to not_if)
* file[/etc/hosts] action create (skipped due to not_if)
* execute[hostnamectl set-hostname example] action run (skipped due to not_if)
(up to date)
[2018-10-22T04:31:24+00:00] WARN: Skipping final node save because override_runlist was given
[2018-10-22T04:31:24+00:00] WARN: Skipping final node save because override_runlist was given
Running handlers:
Running handlers complete
Chef Client finished, 5/11 resources updated in 01 seconds
vagrant@ubuntu-xenial:~$ hostname
example
Если вы используете более старую версию, проверьте эту кулинарную книгу https://github.com/kigster/set-hostname-cookbook