Search code examples
rubyvagrantpuppetpuphpet

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


I am trying to provision my vagrant box running CentOs but I keep getting the this error: Error: has_key(): expects the first argument to be a hash,

Can anyone tell me what it means and how I resolve it?

==> 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.

Here's my Vagrant file:

    # -*- 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']}")

And my 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: ''

I've been stuck for days...


Solution

  • Author of puphpet here.

    The offending code is this:

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

    $vm in this context is $vm = hiera_hash('vagrantfile', {})

    Per your config file, vagrantfile['ssh']['port'] both exists and is a hash as expected. Not sure why the stdlib's has_key() would complain here.

    I ran your config.yaml locally and it spun up fine, with a few exceptions:

    • You have Apache and Nginx both set to install; PuPHPet does not support this and it will not work. You must choose one or the other.
    • You have an empty cron job with key ixrk2utvdrnr
    • You have chosen to install pecl_http - there were recent changes to this package in that another package is now required for it. I have removed this from the default suggested packages on PuPHPet and I recommend you do, too, unless you have a specific need for it. If you do, install the other requirement first. I can't remember the name of it.
    • You've deleted the fpm_pools block - your PHP will not parse because both Nginx and Apache use fpm, which requires pools to be set up.
    • You've got an empty ruby block with key rv_ulhh0yx00do0. I suggest removing it.
    • MySQL 5.6 support has been dropped. I highly recommend rolling back to 5.5, or using MariaDB (my choice).
    • MailCatcher support has been dropped in favor of MailHog, which has no dependencies.

    I also noticed that you are using an older archive. The manifest_file: site.pp tipped me off. Your archive will spin up a Puppet 3.4.x box; please update your box and regenerate your archive. Puppet 4.3.1 now comes installed on new boxes.