Quantcast
Channel: Vimタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 5608

Chefのレシピをデバッグしてみよう。

$
0
0

関連記事

自作したvim-pluginレシピの不具合

chef-shell(旧shef)

  • chef-shellはchef-soloやchef-client環境で使うものである。
  • ホスト(レシピを扱うローカル端末)ではなくゲスト(ノード)で実行する。
  • breakpointを設定して確認する方法についてはのちほど書く。

起動

  • わからないと困るオプションだけ暗記しておく。
    • -s:chef-soloモードで起動
    • -z:chef-clientモードで起動
    • -a:スタンドアロンモードで起動(デフォルト)
    • -c:使用する設定ファイル
    • -j:chef-soloモードのみ有効でrun_listを含むNodeのAttributeとして使うJSONファイルを指定
  • helpを入力するとコマンドとその説明が表示される。
  • 終了したい場合はexitを入力する。
$ cd chef-solo
$ chef-shell -s -c solo.rb -j dna.json

loading configuration: solo.rb
Session type: solo
Loading...done.

This is the chef-shell.
 Chef Version: 12.7.2
 http://www.chef.io/
 http://docs.chef.io/

run `help' for help, `exit' or ^D to quit.

Ohai2u vagrant@dev!
chef (12.7.2)>

レシピモード

  • レシピを確認するとき使う。
  • include_recipeを使って問題があるレシピをインクルードする。
  • run_chefでインクルードしたレシピを実行する。
  • すこし長いがdirectory部分に問題があることはすぐわかった。
  • node['user']が読み込まれてない。
chef (12.7.2)> recipe_mode
chef:recipe (12.7.2)> include_recipe "vim-plugin::default"
chef:recipe (12.7.2)> run_chef
[2016-02-25T11:51:33+00:00] INFO: Processing directory[/home//.vim] action create (vim-plugin::default line 10)[2016-02-25T11:51:33+00:00] DEBUG: Providers for generic directory resource enabled on node include: [Chef::Provider::Directory][2016-02-25T11:51:33+00:00] DEBUG: Provider for action create on resource directory[/home//.vim] is Chef::Provider::Directory

================================================================================
Error executing action `create` on resource 'directory[/home//.vim]'================================================================================

Chef::Exceptions::InsufficientPermissions
-----------------------------------------
Cannot create directory[/home//.vim] at /home//.vim due to insufficient permissions

Resource Declaration:
---------------------
# In /home/vagrant/chef-solo/cookbooks-3/vim-plugin/recipes/default.rb

 10: directory "/home/#{node['user']}/.vim"do
 11:   owner node['user']
 12:   group node['group']
 13:   mode '0755'
 14:   action :create
 15: end
 16:

Compiled Resource:
------------------
# Declared in /home/vagrant/chef-solo/cookbooks-3/vim-plugin/recipes/default.rb:10:in `from_file'

directory("/home//.vim")do
  action [:create]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  path "/home//.vim"
  declared_type :directory
  cookbook_name :"vim-plugin"
  recipe_name "default"
  mode "0755"
end

[2016-02-25T11:51:33+00:00] INFO: Running queued delayed notifications before re-raising exception
Chef::Exceptions::InsufficientPermissions: directory[/home//.vim](vim-plugin::default line 10) had an error: Chef::Exceptions::InsufficientPermissions: Cannot create directory[/home//.vim] at /home//.vim due to insufficient permissions

... snip ...

solo.rb

  • chef-soloの設定ファイル。chef-clientの設定ファイルはclient.rbである。
  • solo.rbを確認したら、environmentがデフォルトになっていた。
  • userやgroupなどのattributeはenvironments(development.json)に保持している。
  • node(dev.json)のchef_environmentもdevelopmentに設定したがそれが適用されてない。
[vagrant@dev chef-solo]$ cat solo.rb
node_name "dev"base= File.expand_path('..', __FILE__)

nodes_path                File.join(base, 'nodes')
role_path                 File.join(base, 'roles')
data_bag_path             File.join(base, 'data_bags')
encrypted_data_bag_secret File.join(base, 'data_bag_key')
environment_path          File.join(base, 'environments')
environment               "_default"
ssl_verify_mode           :verify_peer

cookbook_path []
cookbook_path << File.join(base, 'cookbooks-1') # /Users/devnote/Documents/study/chef/vendor/bundle/ruby/2.2.0/gems/knife-solo-0.5.1/lib/knife-solo/resources/patch_cookbookscookbook_path << File.join(base, 'cookbooks-2')# /Users/devnote/Documents/study/chef/cookbooks
cookbook_path << File.join(base, 'cookbooks-3')# /Users/devnote/Documents/study/chef/site-cookbooks
  • solo.rbの_defaultをdevelopmentで修正した。
$ sed -i -e "s/_default/development/g" solo.rb
$ cat solo.rb
node_name "dev"base= File.expand_path('..', __FILE__)

nodes_path                File.join(base, 'nodes')
role_path                 File.join(base, 'roles')
data_bag_path             File.join(base, 'data_bags')
encrypted_data_bag_secret File.join(base, 'data_bag_key')
environment_path          File.join(base, 'environments')
environment               "development"
ssl_verify_mode           :verify_peer

cookbook_path []
cookbook_path << File.join(base, 'cookbooks-1') # /Users/devnote/Documents/study/chef/vendor/bundle/ruby/2.2.0/gems/knife-solo-0.5.1/lib/knife-solo/resources/patch_cookbookscookbook_path << File.join(base, 'cookbooks-2')# /Users/devnote/Documents/study/chef/cookbooks
cookbook_path << File.join(base, 'cookbooks-3')# /Users/devnote/Documents/study/chef/site-cookbooks
  • レシピモードでもう一度確認したら、今度は正常に実行された。
  • スクリプトには問題がない。
chef:recipe (12.7.2)> include_recipe "vim-plugin::default"
chef:recipe (12.7.2)> run_chef
[2016-02-25T11:57:55+00:00] INFO: Processing directory[/home/vagrant/.vim] action create (vim-plugin::default line 10)[2016-02-25T11:57:55+00:00] DEBUG: Providers for generic directory resource enabled on node include: [Chef::Provider::Directory][2016-02-25T11:57:55+00:00] DEBUG: Provider for action create on resource directory[/home/vagrant/.vim] is Chef::Provider::Directory
[2016-02-25T11:57:55+00:00] DEBUG: Found target_mode== current_mode, not updating mode
[2016-02-25T11:57:55+00:00] DEBUG: Found target_uid== current_uid, not updating owner
[2016-02-25T11:57:55+00:00] DEBUG: Found target_gid== current_gid, not updating group
[2016-02-25T11:57:55+00:00] INFO: Processing directory[/home/vagrant/.vim/backup] action create (vim-plugin::default line 18)[2016-02-25T11:57:55+00:00] DEBUG: Providers for generic directory resource enabled on node include: [Chef::Provider::Directory][2016-02-25T11:57:55+00:00] DEBUG: Provider for action create on resource directory[/home/vagrant/.vim/backup] is Chef::Provider::Directory
[2016-02-25T11:57:55+00:00] DEBUG: Found target_mode== current_mode, not updating mode
[2016-02-25T11:57:55+00:00] DEBUG: Found target_uid== current_uid, not updating owner
[2016-02-25T11:57:55+00:00] DEBUG: Found target_gid== current_gid, not updating group
[2016-02-25T11:57:55+00:00] INFO: Processing directory[/home/vagrant/.vim/bundle] action create (vim-plugin::default line 18)[2016-02-25T11:57:55+00:00] DEBUG: Providers for generic directory resource enabled on node include: [Chef::Provider::Directory][2016-02-25T11:57:55+00:00] DEBUG: Provider for action create on resource directory[/home/vagrant/.vim/bundle] is Chef::Provider::Directory
[2016-02-25T11:57:55+00:00] DEBUG: Found target_mode== current_mode, not updating mode
[2016-02-25T11:57:55+00:00] DEBUG: Found target_uid== current_uid, not updating owner
[2016-02-25T11:57:55+00:00] DEBUG: Found target_gid== current_gid, not updating group
[2016-02-25T11:57:55+00:00] INFO: Processing directory[/home/vagrant/.vim/swap] action create (vim-plugin::default line 18)[2016-02-25T11:57:55+00:00] DEBUG: Providers for generic directory resource enabled on node include: [Chef::Provider::Directory][2016-02-25T11:57:55+00:00] DEBUG: Provider for action create on resource directory[/home/vagrant/.vim/swap] is Chef::Provider::Directory
[2016-02-25T11:57:55+00:00] DEBUG: Found target_mode== current_mode, not updating mode
[2016-02-25T11:57:55+00:00] DEBUG: Found target_uid== current_uid, not updating owner
[2016-02-25T11:57:55+00:00] DEBUG: Found target_gid== current_gid, not updating group
[2016-02-25T11:57:55+00:00] INFO: Processing execute[install neobundle] action run (vim-plugin::default line 26)[2016-02-25T11:57:55+00:00] DEBUG: Skipping execute[install neobundle] due to not_if ruby block
[2016-02-25T11:57:55+00:00] INFO: Processing cookbook_file[/home/vagrant/.vimrc_scss_indent] action create (vim-plugin::default line 36)[2016-02-25T11:57:55+00:00] DEBUG: cookbook_file[/home/vagrant/.vimrc_scss_indent] checksumming file at /home/vagrant/.vimrc_scss_indent.
[2016-02-25T11:57:55+00:00] DEBUG: cookbook_file[/home/vagrant/.vimrc_scss_indent] staging /home/vagrant/chef-solo/cookbooks-3/vim-plugin/files/default/.vimrc_scss_indent to /home/vagrant/..vimrc_scss_indent20160225-6651-1b7m1of
[2016-02-25T11:57:55+00:00] DEBUG: calculating checksum of /home/vagrant/..vimrc_scss_indent20160225-6651-1b7m1of to compare with 05be8b3325aa3c67568c37216114a0a530a55dc9d199d7476a82d306b969222e
[2016-02-25T11:57:55+00:00] DEBUG: Found target_mode== current_mode, not updating mode
[2016-02-25T11:57:55+00:00] DEBUG: Found target_uid== current_uid, not updating owner
[2016-02-25T11:57:55+00:00] DEBUG: Found target_gid== current_gid, not updating group
[2016-02-25T11:57:55+00:00] INFO: Processing cookbook_file[/home/vagrant/.vimrc] action create (vim-plugin::default line 36)[2016-02-25T11:57:55+00:00] DEBUG: cookbook_file[/home/vagrant/.vimrc] checksumming file at /home/vagrant/.vimrc.
[2016-02-25T11:57:55+00:00] DEBUG: cookbook_file[/home/vagrant/.vimrc] staging /home/vagrant/chef-solo/cookbooks-3/vim-plugin/files/default/.vimrc to /home/vagrant/..vimrc20160225-6651-1i2xivg
[2016-02-25T11:57:55+00:00] DEBUG: calculating checksum of /home/vagrant/..vimrc20160225-6651-1i2xivg to compare with bd258180199e8ac6b76be5c6de6067e4396d5563490666a932ebe1bfc02e0133
[2016-02-25T11:57:55+00:00] DEBUG: Found target_mode== current_mode, not updating mode
[2016-02-25T11:57:55+00:00] DEBUG: Found target_uid== current_uid, not updating owner
[2016-02-25T11:57:55+00:00] DEBUG: Found target_gid== current_gid, not updating group
[2016-02-25T11:57:55+00:00] INFO: Processing execute[install vim plugin via neobundle] action run (vim-plugin::default line 43)[2016-02-25T11:57:55+00:00] DEBUG: Providers for generic execute resource enabled on node include: [Chef::Provider::Execute][2016-02-25T11:57:55+00:00] DEBUG: Provider for action run on resource execute[install vim plugin via neobundle] is Chef::Provider::Execute
not found in 'runtimepath': "ftdetect/*.vim"
not found in 'runtimepath': "colors/mopkai.vim"
Error detected while processing /home/vagrant/.vimrc:
line  707:
E185: Cannot find color scheme 'mopkai'[neobundle]command AlpacaTagsSet is not found.
[neobundle] Update started: (2016/02/25 11:57:55)
not found in 'runtimepath': "autoload/vimproc.vim"
not found in 'runtimepath': "autoload/vimproc.vim"
not found in 'runtimepath': "autoload/vimproc.vim"[neobundle]( 1/65)[] vimproc.vim
not found in 'runtimepath': "autoload/vimproc.vim"
not found in 'runtimepath': "autoload/vimproc.vim"
not found in 'runtimepath': "autoload/vimproc.vim"

... snip ...

neobundle](65/65)[====================] vim-haml
not found in 'runtimepath': "autoload/vimproc.vim"
not found in 'runtimepath': "autoload/vimproc.vim"
not found in 'runtimepath': "autoload/vimproc.vim"[neobundle](65/65): |vim-haml| Updated
[neobundle][neobundle] Installed bundles:
[neobundle]   vimproc.vim

... snip ...

[neobundle]   vim-haml
[neobundle] Update done: (2016/02/25 12:01:06)[2016-02-25T12:01:06+00:00] INFO: execute[install vim plugin via neobundle] ran successfully=> true
chef:recipe (12.7.2)>
  • solo.rbはchef-soloを設置するとき-Eオプションで指定しないとデフォルト値になってしまう。
  • 最初からやり直し
    • vagrant destroy
    • vagrant up
    • bin/knife solo bootstrap dev -E development
% bin/knife solo bootstrap dev -E development
Bootstrapping Chef...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100200221002002200163650  0:00:01  0:00:01 --:--:-- 59767
Getting information for chef stable 12.7.2 for el...
downloading https://omnitruck-direct.chef.io/stable/chef/metadata?v=12.7.2&p=el&pv=6&m=x86_64
  to file /tmp/install.sh.3278/metadata.txt
trying wget...
url https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-12.7.2-1.el6.x86_64.rpm
md5 8c3ba2e797fc852fc557b0e7157556cc
sha256  6af0eb1c7706fc6a36f74ae9f590135e37e6206f2fe7d5a1760c1e2da1b36068
version 12.7.2downloaded metadata file looks valid...
downloading https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chef-12.7.2-1.el6.x86_64.rpm
  to file /tmp/install.sh.3278/chef-12.7.2-1.el6.x86_64.rpm
trying wget...
Comparing checksum with sha256sum...
Installing chef 12.7.2
installing with rpm...
警告: /tmp/install.sh.3278/chef-12.7.2-1.el6.x86_64.rpm: ヘッダ V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY
準備中...                ########################################### [100%]
   1:chef                   ########################################### [100%]
Thank you for installing Chef!
Running Chef on dev...
Installing Berkshelf cookbooks to 'cookbooks'...
Resolving cookbook dependencies...
Using 7-zip (1.0.2)
Using chef-pry (0.2.0)
Using vim (2.0.1)
Using yum (3.10.0)
Using chef_handler (1.3.0)
Using build-essential (2.3.1)
Using yum-epel (0.6.5)
Using windows (1.39.1)
Vendoring 7-zip (1.0.2) to cookbooks/7-zip
Vendoring build-essential (2.3.1) to cookbooks/build-essential
Vendoring chef-pry (0.2.0) to cookbooks/chef-pry
Vendoring chef_handler (1.3.0) to cookbooks/chef_handler
Vendoring vim (2.0.1) to cookbooks/vim
Vendoring windows (1.39.1) to cookbooks/windows
Vendoring yum (3.10.0) to cookbooks/yum
Vendoring yum-epel (0.6.5) to cookbooks/yum-epel
Uploading the kitchen...
Generating solo config...
Running Chef: sudo chef-solo -c ~/chef-solo/solo.rb -j ~/chef-solo/dna.json
Starting Chef Client, version 12.7.2
Compiling Cookbooks...
Converging 31 resources
Recipe: yum-epel::default
  * yum_repository[epel] action create
    * template[/etc/yum.repos.d/epel.repo] action create
      - create new file /etc/yum.repos.d/epel.repo
      - update content in file /etc/yum.repos.d/epel.repo from none to d02c1f
      --- /etc/yum.repos.d/epel.repo    2016-02-26 02:59:05.228446569 +0000
      +++ /etc/yum.repos.d/.epel.repo20160226-3435-uj6rv8   2016-02-26 02:59:05.228446569 +0000
      @@ -1 +1,11 @@
      +# This file was generated by Chef
      +# Do NOT modify this file by hand.
      +
      +[epel]
      +name=Extra Packages for Enterprise Linux 6 - $basearch
      +enabled=1
      +failovermethod=priority
      +gpgcheck=1
      +gpgkey=https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
      +mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
      - change mode from '' to '0644'
      - restore selinux security context
    * execute[yum clean metadata epel] action run
      - execute yum clean metadata --disablerepo=* --enablerepo=epel
    * execute[yum-makecache-epel] action run
      - execute yum -q -y makecache --disablerepo=* --enablerepo=epel
    * ruby_block[yum-cache-reload-epel] action create
      - execute the ruby block yum-cache-reload-epel
    * execute[yum clean metadata epel] action nothing (skipped due to action :nothing)
    * execute[yum-makecache-epel] action nothing (skipped due to action :nothing)
    * ruby_block[yum-cache-reload-epel] action nothing (skipped due to action :nothing)

Recipe: yum-update::default
  * execute[yum-update] action run
    - execute yum -y update
Recipe: mariadb::default
  * cookbook_file[/etc/yum.repos.d/MariaDB.repo] action create
    - create new file /etc/yum.repos.d/MariaDB.repo
    - update content in file /etc/yum.repos.d/MariaDB.repo from none to 3e5392
    --- /etc/yum.repos.d/MariaDB.repo   2016-02-26 03:01:05.259432022 +0000
    +++ /etc/yum.repos.d/.MariaDB.repo20160226-3435-12k147j 2016-02-26 03:01:05.259432021 +0000
    @@ -1 +1,8 @@
    +# MariaDB 10.1 CentOS repository list - created 2016-02-21 00:19 UTC
    +# http://mariadb.org/mariadb/repositories/
    +[mariadb]
    +name = MariaDB
    +baseurl = http://yum.mariadb.org/10.1/centos6-amd64
    +gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    +gpgcheck=1
    - change mode from '' to '0644'
    - change owner from '' to 'root'
    - change group from '' to 'root'
    - restore selinux security context
  * yum_package[MariaDB-server] action install
    - install version 10.1.12-1.el6 of package MariaDB-server
  * yum_package[MariaDB-client] action install (up to date)
  * yum_package[MariaDB-devel] action install
    - install version 10.1.12-1.el6 of package MariaDB-devel
Recipe: ruby-env::default
  * yum_package[gcc] action install
    - install version 4.4.7-16.el6 of package gcc
  * yum_package[git] action install
    - install version 1.7.1-3.el6_4.1 of package git
  * yum_package[openssl-devel] action install
    - install version 1.0.1e-42.el6_7.2 of package openssl-devel
  * yum_package[readline-devel] action install
    - install version 6.0-4.el6 of package readline-devel
  * git[/home/vagrant/.rbenv] action sync
    - clone from https://github.com/rbenv/rbenv.git into /home/vagrant/.rbenv
    - checkout ref 29b4da77370af0a3413dce00a72c7631302a2b25 branch HEAD
  * template[.bash_profile] action create
    - update content in file /home/vagrant/.bash_profile from 173704 to cc39f6
    --- /home/vagrant/.bash_profile 2015-07-23 18:55:47.000000000 +0000
    +++ /home/vagrant/..bash_profile20160226-3435-14ivv4w   2016-02-26 03:03:00.602074477 +0000
    @@ -2,12 +2,12 @@

     # Get the aliases and functionsif[ -f ~/.bashrc ];then
    -   . ~/.bashrc
    +  . ~/.bashrc
     fi# User specific environment and startup programs
    -
     PATH=$PATH:$HOME/bin

    -export PATH
    +export PATH="$HOME/.rbenv/bin:$PATH"
    +eval "$(rbenv init -)"
    - restore selinux security context
  * directory[/home/vagrant/.rbenv/plugins] action create
    - create new directory /home/vagrant/.rbenv/plugins
    - change mode from '' to '0755'
    - change owner from '' to 'vagrant'
    - change group from '' to 'vagrant'
    - restore selinux security context
  * git[/home/vagrant/.rbenv/plugins/ruby-build] action sync
    - clone from https://github.com/rbenv/ruby-build.git into /home/vagrant/.rbenv/plugins/ruby-build
    - checkout ref ae20bb1aa64ca8d7f28dd2315c1fe8c489149b5c branch HEAD
  * execute[rbenv install 2.3.0] action run
    - execute /home/vagrant/.rbenv/bin/rbenv install 2.3.0
  * execute[rbenv global 2.3.0] action run
    - execute /home/vagrant/.rbenv/bin/rbenv global 2.3.0
  * execute[gem install rbenv-rehash] action run
    - execute /home/vagrant/.rbenv/shims/gem install rbenv-rehash
  * execute[gem install bundler] action run
    - execute /home/vagrant/.rbenv/shims/gem install bundler
Recipe: lua::default
  * yum_package[lua-devel] action install
    - install version 5.1.4-4.1.el6 of package lua-devel
  * git[/var/chef/cache/luajit] action sync
    - clone from http://luajit.org/git/luajit-2.0.git into /var/chef/cache/luajit
    - checkout ref a44388967763d0f7f5f78dfd71703437afa69fc0 branch HEAD
  * bash[install luajit] action run
    - execute "bash""/tmp/chef-script20160226-3435-1rheo8o"
Recipe: vim::package
  * yum_package[vim-minimal, vim-enhanced] action install
    - install version 7.4.629-5.el6 of package vim-enhanced
  * yum_package[] action install (up to date)
Recipe: vim-plugin::default
  * directory[/home/vagrant/.vim] action create
    - create new directory /home/vagrant/.vim
    - change mode from '' to '0755'
    - change owner from '' to 'vagrant'
    - change group from '' to 'vagrant'
    - restore selinux security context
  * directory[/home/vagrant/.vim/backup] action create
    - create new directory /home/vagrant/.vim/backup
    - change mode from '' to '0755'
    - change owner from '' to 'vagrant'
    - change group from '' to 'vagrant'
    - restore selinux security context
  * directory[/home/vagrant/.vim/bundle] action create
    - create new directory /home/vagrant/.vim/bundle
    - change mode from '' to '0755'
    - change owner from '' to 'vagrant'
    - change group from '' to 'vagrant'
    - restore selinux security context
  * directory[/home/vagrant/.vim/swap] action create
    - create new directory /home/vagrant/.vim/swap
    - change mode from '' to '0755'
    - change owner from '' to 'vagrant'
    - change group from '' to 'vagrant'
    - restore selinux security context
  * execute[install neobundle] action run
    - execute curl -L https://raw.githubusercontent.com/Shougo/neobundle.vim/master/bin/install.sh | sh
  * cookbook_file[/home/vagrant/.vimrc_scss_indent] action create
    - create new file /home/vagrant/.vimrc_scss_indent
    - update content in file /home/vagrant/.vimrc_scss_indent from none to 05be8b
    --- /home/vagrant/.vimrc_scss_indent    2016-02-26 03:08:03.382388857 +0000
    +++ /home/vagrant/..vimrc_scss_indent20160226-3435-oumghu   2016-02-26 03:08:03.382388857 +0000
    @@ -1 +1,48 @@
    +setlocal indentexpr=GetMyIndent()
    +function! GetMyIndent()
    +    let cline= getline(v:lnum)
    +
    +    " Find a non-blank line above the current line.    +    let lnum = prevnonblank(v:lnum - 1)    +    " Hit the start of the file, use zero indent.
    +    iflnum== 0
    +        return 0
    +    endif
    +    let line= getline(lnum)
    +    let ind= indent(lnum)
    +
    +    " Indent blocks enclosed by {}, (), or []    +    " Find a real opening brace
    +    let bracepos= match(line, '[(){}\[\]]', matchend(line, '^\s*[)}\]]'))
    +    while bracepos != -1


    +        let brace= strpart(line, bracepos, 1)
    +        ifbrace=='('||brace=='{'||brace=='['
    +            let ind= ind + &sw
    +        else
    +            let ind= ind - &sw
    +        endif
    +        let bracepos= match(line, '[(){}\[\]]', bracepos + 1)
    +    endwhile
    +    let bracepos= matchend(cline, '^\s*[)}\]]')
    +    if bracepos != -1
    +        let ind= ind - &sw
    +    endif
    +
    +    return ind
    +endfunction
    +
    +setlocal expandtab
    +setlocal tabstop=4
    +setlocal shiftwidth=4
    +setlocal softtabstop=0
    +
    +if !exists('b:undo_indent')
    +    let b:undo_indent =''
    +endif
    +
    +let b:undo_indent ='setlocal '.join([
    +      \ 'tabstop<',
    +      \ 'shiftwidth<',
    +      \ 'softtabstop<',
    +      \ ])
    - change mode from '' to '0644'
    - change owner from '' to 'vagrant'
    - change group from '' to 'vagrant'
    - restore selinux security context
  * cookbook_file[/home/vagrant/.vimrc] action create
    - create new file /home/vagrant/.vimrc
    - update content in file /home/vagrant/.vimrc from none to bd2581
    (new content is binary, diff output suppressed)
    - change mode from '' to '0644'
    - change owner from '' to 'vagrant'
    - change group from '' to 'vagrant'
    - restore selinux security context
  * execute[install vim plugin via neobundle] action run
    - execute /home/vagrant/.vim/bundle/neobundle.vim/bin/neoinstall

Running handlers:
Running handlers complete
Chef Client finished, 33/38 resources updated in 08 minutes 59 seconds
  • しかし、今度もneoinstall処理が早かった。ノードを調べたがやはり設置されてない。

script処理

  • リソース内で定義したスクリプトはroot権限で実行される。
  • user、group、environmentを指定するとそのユーザで実行されると思っていたが、そうではないみたいだ。
  • 結論から言うと次のようにすればできる。
command"sudo -u #{node['user']} /home/#{node['user']}/.vim/bundle/neobundle.vim/bin/neoinstall"
  • 最終的には次のように変更した。
    • ユーザを指定してスクリプトを実行する。
    • 実行が終わったら.neoinstalledという仮のファイルを生成する。
    • .neoinstalledというファイルが存在しない場合に限ってスクリプトを実行するようになる。
bash'install vim plugin via neobundle'dousernode['user']groupnode['group']cwd"/home/#{node['user']}"environment'HOME'=>"/home/#{node['user']}"code<<-EOH    sudo -u #{node['user']} ~/.vim/bundle/neobundle.vim/bin/neoinstall    touch .neoinstalled  EOHnot_if{File.exists?("/home/#{node['user']}/.neoinstalled")}end

結論

  • Attributesの記述方法がnode、environments、recipe中のattributeがバラバラである。優先順位はともかく記述方法は同じでほしい。
  • Attributesと関連してかなりソースコードを修正した。
  • ソースコードを確認する

感想

  • Chefは難しい。学習コストが高い。
  • 日本語の本が少ない。入門書にはかなりいい良書が2~3冊あるが、もっと知りたい場合は公式ドキュメントに依存するしかない。まあ当たり前だな。

参考


Viewing all articles
Browse latest Browse all 5608

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>