Error: has_key(): expects the first argument to be a hash,

Error: has_key(): expects the first argument to be a hash,

我正在尝试配置我的 vagrant box 运行 CentOs 但我一直收到此错误:Error: has_key(): expects the first argument to be a hash,

谁能告诉我这是什么意思,我是怎么解决的?

==> default: Running provisioner: shell...
    default: Running: /var/folders/mr/qmf1r_317zl1ryd9dp8nj1nml2yjr7/T/vagrant-shell20151211-6577-1370bsm.sh
==> default: Running provisioner: shell...
    default: Running: /var/folders/mr/qmf1r_317zl1ryd9dp8nj1nml2yjr7/T/vagrant-shell20151211-6577-19k2u5d.sh
==> default: Running provisioner: shell...
    default: Running: /var/folders/mr/qmf1r_317zl1ryd9dp8nj1nml2yjr7/T/vagrant-shell20151211-6577-1ral51j.sh
==> default: Running provisioner: puppet...
==> default: Running Puppet with site.pp...
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/composer/lib/facter/composer_home.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/concat/lib/facter/concat_basedir.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/firewall/lib/facter/ip6tables_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/firewall/lib/facter/iptables_persistent_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/firewall/lib/facter/iptables_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/git/lib/facter/git_exec_path.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/git/lib/facter/git_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/java/lib/facter/java_major_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/java/lib/facter/java_patch_level.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/java/lib/facter/java_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/php/lib/facter/php_fact_extension_dir.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/php/lib/facter/php_fact_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/puppi/lib/facter/last_run.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/puppi/lib/facter/puppi_projects.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/puppi/lib/facter/windows_common_appdata.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/rabbitmq/lib/facter/rabbitmq_erlang_cookie.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/rvm/lib/facter/rvm_installed.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/rvm/lib/facter/rvm_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/staging/lib/facter/staging_http_get.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/staging/lib/facter/staging_windir.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/stdlib/lib/facter/facter_dot_d.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/stdlib/lib/facter/pe_version.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/stdlib/lib/facter/puppet_vardir.rb
==> default: Info: Loading facts in /tmp/vagrant-puppet/modules-86824c4326e330d264f84aded5219b9a/stdlib/lib/facter/root_home.rb
==> default: Error: has_key(): expects the first argument to be a hash, got false which is of type FalseClass at /tmp/vagrant-puppet/manifests-893fcda21077f5a583c2dbbba8515c0a/nodes/firewall.pp:41 on node domain.local
==> default: Error: has_key(): expects the first argument to be a hash, got false which is of type FalseClass at /tmp/vagrant-puppet/manifests-893fcda21077f5a583c2dbbba8515c0a/nodes/firewall.pp:41 on node domain.local
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

这是我的 Vagrant 文件:

    # -*- mode: ruby -*-

    dir = File.dirname(File.expand_path(__FILE__))

    require 'yaml'
    require "#{dir}/puphpet/ruby/deep_merge.rb"

    configValues = YAML.load_file("#{dir}/puphpet/config.yaml")

    if File.file?("#{dir}/puphpet/config-custom.yaml")
      custom = YAML.load_file("#{dir}/puphpet/config-custom.yaml")
      configValues.deep_merge!(custom)
    end

    data = configValues['vagrantfile']

    Vagrant.require_version '>= 1.6.0'

eval File.read("#{dir}/puphpet/vagrant/Vagrantfile-#{data['target']}")

还有我的config.yaml

vagrantfile:
    target: local
    vm:
        box: puphpet/centos65-x64
        box_url: puphpet/centos65-x64
        hostname: domain.local
        memory: '1024'
        cpus: '1'
        chosen_provider: virtualbox
        network:
            private_network: 192.168.56.10
            forwarded_port:
                vflnp_wmozbmczs2bq:
                    host: '6740'
                    guest: '22'
        post_up_message: ''
        provider:
            virtualbox:
                modifyvm:
                    natdnshostresolver1: 'on'
                showgui: '0'
            vmware:
                numvcpus: 1
            parallels:
                cpus: 1
        provision:
            puppet:
                manifests_path: puphpet/puppet
                manifest_file: site.pp
                module_path: puphpet/puppet/modules
                options:
                    - '--verbose'
                    - '--hiera_config /vagrant/puphpet/puppet/hiera.yaml'
                    - '--parser future'
        synced_folder:
            vflsf_yd7pvw7djld6:
                source: ./www
                target: /var/www
                sync_type: default
                smb:
                    smb_host: ''
                    smb_username: ''
                    smb_password: ''
                rsync:
                    args:
                        - '--verbose'
                        - '--archive'
                        - '-z'
                    exclude:
                        - .vagrant/
                        - .git/
                    auto: 'true'
                owner: www-data
                group: www-data
        usable_port_range:
            start: 10200
            stop: 10500
    ssh:
        host: null
        port: null
        private_key_path: null
        username: vagrant
        guest_port: null
        keep_alive: true
        forward_agent: false
        forward_x11: false
        shell: 'bash -l'
    vagrant:
        host: detect
server:
    install: '1'
    packages:
        - vim-common
        - htop
        - telnet
users_groups:
    install: '1'
    groups: {  }
    users: {  }
locale:
    install: '1'
    settings:
        default_locale: ''
        locales:
            - en_GB.UTF-8
            - en_US.UTF-8
firewall:
    install: '1'
    rules: {  }
cron:
    install: '1'
    jobs:
        cj_lvl6djqwp8s0:
            name: 'Magento Cronjob (Default)'
            user: vagrant
            command: 'php /var/www/cron.php -mdefault'
            minute: '*/1'
            hour: '*'
            weekday: '*'
            month: '*'
        ixrk2utvdrnr:
            monthday: ''
        cj_0n3kz18p4mxl:
            name: 'Magento Cronjob (Always)'
            user: vagrant
            command: 'php /var/www/cron.php -malways'
            minute: '*/1'
            hour: '*'
            weekday: '*'
            month: '*'
            monthday: ''
nginx:
    install: '1'
    settings:
        default_vhost: 1
        proxy_buffer_size: 128k
        proxy_buffers: '4 256k'
    upstreams: {  }
    vhosts:
        myvm:
            server_name: my-vm.magedomain.com
            www_root: /var/www/
            listen_port: '80'
            index_files:
                - index.html
                - index.php
            client_max_body_size: 1m
            ssl: '1'
            ssl_cert: /vagrant/magedomain.cert
            ssl_key: /vagrant/magenrdomain.key
            ssl_port: '443'
            ssl_protocols: ''
            ssl_ciphers: ''
            rewrite_to_https: '0'
            spdy: '1'
            locations:
                myvm1:
                    location: /
                    autoindex: 'off'
                    internal: 'false'
                    try_files:
                        - $uri
                        - $uri/
                        - /index.php$is_args$args
                    fastcgi: ''
                    fastcgi_index: ''
                    fastcgi_split_path: ''
                myvm2:
                    location: '~ \.php$'
                    autoindex: 'off'
                    internal: 'false'
                    try_files:
                        - $uri
                        - $uri/
                        - /index.php$is_args$args
                    fastcgi: '127.0.0.1:9000'
                    fastcgi_index: index.php
                    fastcgi_split_path: '^(.+\.php)(/.*)$'
                    fast_cgi_params_extra:
                        - 'SCRIPT_FILENAME $request_filename'
    proxies: {  }
apache:
    install: '1'
    settings:
        user: www-data
        group: www-data
        default_vhost: true
        manage_user: false
        manage_group: false
        sendfile: 0
    modules:
        - deflate
        - expires
        - headers
        - info
        - proxy_fcgi
        - proxy
        - rewrite
    vhosts:
        av_yy8ib55ooip9:
            servername: my-vm.magedomain.com
            docroot: /var/www/domain.local
            port: '80'
            setenv:
                - 'MAGE_IS_DEVELOPER_MODE 1'
            custom_fragment: ''
            ssl: '0'
            ssl_cert: ''
            ssl_key: 'ssh'
            ssl_chain: ''
            ssl_certs_dir: ''
            ssl_protocol: ''
            ssl_cipher: ''
            directories:
                avd_0jq2hk9z6ud2:
                    path: /var/www/domain.local
                    options:
                        - Indexes
                        - FollowSymlinks
                        - MultiViews
                    allow_override:
                        - All
                    require:
                        - 'all granted'
                    custom_fragment: ''
                    files_match:
                        avdfm_urjoe5v1vbg9:
                            path: \.php$
                            sethandler: 'proxy:fcgi://127.0.0.1:9000'
                            custom_fragment: ''
                            provider: filesmatch
                    provider: directory
        av_1hkh1wvj5dbl:
            servername: my-vm.magedomain.com
            docroot: /var/www/domain.local
            port: '443'
            setenv:
                - 'MAGE_IS_DEVELOPER_MODE 1'
            custom_fragment: ''
            ssl: '0'
            ssl_cert: ''
            ssl_key: ''
            ssl_chain: ''
            ssl_certs_dir: ''
            ssl_protocol: ''
            ssl_cipher: ''
            directories:
                avd_dyxsni5u8zuk:
                    path: /var/www/domain.local
                    options:
                        - Indexes
                        - FollowSymlinks
                        - MultiViews
                    allow_override:
                        - All
                    require:
                        - 'all granted'
                    custom_fragment: ''
                    files_match:
                        avdfm_j22brvo6hoy2:
                            path: \.php$
                            sethandler: 'proxy:fcgi://127.0.0.1:9000'
                            custom_fragment: ''
                            provider: filesmatch
                    provider: directory
php:
    install: '1'
    settings:
        version: '54'
    modules:
        php:
            - cli
            - intl
            - mcrypt
            - gd
            - curl
            - mysql
            - tidy
            - mbstring
            - soap
        pear: {  }
        pecl:
            - pecl_http
    ini:
        display_errors: 'On'
        error_reporting: '-1'
        session.save_path: /var/lib/php/session
    fpm_ini:
        error_log: /var/log/php-fpm.log
    fpm_pools: {  }
    composer: '1'
    composer_home: ''
xdebug:
    install: '1'
    settings:
        xdebug.default_enable: '1'
        xdebug.remote_autostart: '0'
        xdebug.remote_connect_back: '0'
        xdebug.remote_host: 10.0.2.2
        xdebug.remote_enable: '1'
        xdebug.remote_handler: dbgp
        xdebug.remote_port: '9000'
        xdebug.idekey: PHPSTORM
blackfire:
    install: '0'
    settings:
        server_id: ''
        server_token: ''
        agent:
            http_proxy: ''
            https_proxy: ''
            log_file: stderr
            log_level: '1'
        php:
            agent_timeout: '0.25'
            log_file: ''
            log_level: '1'
xhprof:
    install: '0'
wpcli:
    install: '0'
    version: ''
drush:
    install: '0'
    version: 6.3.0
ruby:
    install: '1'
    versions:
        rv_ulhh0yx00do0:
            version: ''
python:
    install: '1'
    packages: {  }
    versions:
        pyenv_i0cj5bnane3r:
            version: 2.6.9
nodejs:
    install: '0'
    npm_packages:
        - grunt-cli
        - bower
hhvm:
    install: '0'
    nightly: 0
    composer: '1'
    composer_home: ''
    settings: {  }
    server_ini: {  }
    php_ini: {  }
mysql:
    install: '1'
    settings:
        version: '5.6'
        root_password: root
        override_options: {  }
    adminer: 0
    users:
        mysqlnu_y57jb5rdz96u:
            name: magento
            password: root
    databases:
        mysqlnd_8qefzcbhh56c:
            name: magento
            sql: ''
    grants:
        mysqlng_oo7pkf43pn7i:
            user: magento
            table: 'magento.*'
            privileges:
                - ALL
mariadb:
    install: '0'
    settings:
        version: '10.0'
        root_password: '123'
        override_options: {  }
    adminer: 0
    users:
        mariadbnu_uqqk6zprkq5l:
            name: dbuser
            password: '123'
    databases:
        mariadbnd_0fp5v72v5gls:
            name: dbname
            sql: ''
    grants:
        mariadbng_d9hlksvme32e:
            user: dbuser
            table: '*.*'
            privileges:
                - ALL
postgresql:
    install: '0'
    settings:
        global:
            encoding: UTF8
            version: '9.3'
        server:
            postgres_password: ''
    databases: {  }
    users: {  }
    grants: {  }
    adminer: 0
mongodb:
    install: '0'
    settings:
        auth: 1
        bind_ip: 127.0.0.1
        port: '27017'
    databases: {  }
redis:
    install: '0'
    settings:
        conf_port: '6379'
sqlite:
    install: '0'
    adminer: 0
    databases: {  }
mailcatcher:
    install: '1'
    settings:
        smtp_ip: 0.0.0.0
        smtp_port: 1025
        http_ip: 0.0.0.0
        http_port: '1080'
        mailcatcher_path: /usr/local/rvm/wrappers/default
        from_email_method: headers
beanstalkd:
    install: '0'
    settings:
        listenaddress: 0.0.0.0
        listenport: '13000'
        maxjobsize: '65535'
        maxconnections: '1024'
        binlogdir: /var/lib/beanstalkd/binlog
        binlogfsync: null
        binlogsize: '10485760'
    beanstalk_console: 0
rabbitmq:
    install: '0'
    settings:
        port: '5672'
    users: {  }
    vhosts: {  }
    plugins: {  }
elastic_search:
    install: '0'
    settings:
        version: null
        java_install: true
solr:
    install: '0'
    settings:
        version: 4.10.2
        port: ''

我卡了好几天了...

这里是 puphpet 的作者。

违规代码是这样的:

if has_key($vm, 'ssh') and has_key($vm['ssh'], 'port') {

$vm 在这种情况下是 $vm = hiera_hash('vagrantfile', {})

根据您的配置文件,vagrantfile['ssh']['port'] 既存在又是预期的散列。不知道为什么 stdlib 的 has_key() 会在这里抱怨。

我 运行 你的 config.yaml 在本地,它运行良好,但有一些例外:

  • 您已将 Apache 和 Nginx 都设置为安装; PuPHPet 不支持这个,它不会工作。您必须选择其中之一。
  • 您有一个空的 cron 作业,键为 ixrk2utvdrnr
  • 您已选择安装 pecl_http - 此软件包最近发生了变化,现在需要另一个软件包。我已将其从 PuPHPet 上的默认建议包中删除,我建议您也这样做,除非您有特殊需要。如果这样做,请先安装其他要求。我不记得它的名字了。
  • 您已删除 fpm_pools 块 - 您的 PHP 将无法解析,因为 Nginx 和 Apache 都使用 fpm,这需要设置池。
  • 你有一个空的 ruby 块,键为 rv_ulhh0yx00do0。我建议删除它。
  • MySQL 5.6 支持已被取消。我强烈建议回滚到 5.5,或使用 MariaDB(我的选择)。
  • 已放弃对 MailCatcher 的支持,取而代之的是 MailHog,它没有依赖项。

我还注意到您使用的是旧存档。 manifest_file: site.pp 告诉我。您的存档将启动一个 Puppet 3.4.x 框;请更新您的盒子并重新生成您的档案。 Puppet 4.3.1 现在安装在新盒子上。