oomichi / try-kubernetes

11 stars 5 forks source link

Failed to run Kubespray vagrant #116

Closed oomichi closed 2 years ago

oomichi commented 2 years ago

Summary:

Error message:

$ vagrant up
...
==> k8s-3: Running provisioner: shell...
    k8s-3: Running: inline script
==> k8s-3: Running provisioner: shell...
    k8s-3: Running: inline script
==> k8s-3: Running provisioner: shell...
    k8s-3: Running: inline script
==> k8s-3: Running provisioner: ansible...
Vagrant gathered an unknown Ansible version:

ansible [core 2.12.3]
  config file = /home/oomichi/kubespray/ansible.cfg
  configured module search path = ['/home/oomichi/kubespray/library']
  ansible python module location = /home/oomichi/kubespray-venv/lib/python3.8/site-packages/ansible
  ansible collection location = /home/oomichi/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/oomichi/kubespray-venv/bin/ansible
  python version = 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0]
  jinja version = 2.11.3
  libyaml = True

and falls back on the compatibility mode '1.8'.

Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode

==> k8s-3: Vagrant has detected a host range pattern in the `groups` option.
==> k8s-3: Vagrant doesn't fully check the validity of these parameters!
==> k8s-3: 
==> k8s-3: Please check https://docs.ansible.com/ansible/intro_inventory.html#hosts-and-groups
==> k8s-3: for more information.
    k8s-3: Running ansible-playbook...
usage: ansible-playbook [-h] [--version] [-v] [--private-key PRIVATE_KEY_FILE]
                        [-u REMOTE_USER] [-c CONNECTION] [-T TIMEOUT]
                        [--ssh-common-args SSH_COMMON_ARGS]
                        [--sftp-extra-args SFTP_EXTRA_ARGS]
                        [--scp-extra-args SCP_EXTRA_ARGS]
                        [--ssh-extra-args SSH_EXTRA_ARGS]
                        [-k | --connection-password-file CONNECTION_PASSWORD_FILE]
                        [--force-handlers] [--flush-cache] [-b]
                        [--become-method BECOME_METHOD]
                        [--become-user BECOME_USER]
                        [-K | --become-password-file BECOME_PASSWORD_FILE]
                        [-t TAGS] [--skip-tags SKIP_TAGS] [-C]
                        [--syntax-check] [-D] [-i INVENTORY] [--list-hosts]
                        [-l SUBSET] [-e EXTRA_VARS] [--vault-id VAULT_IDS]
                        [--ask-vault-password | --vault-password-file VAULT_PASSWORD_FILES]
                        [-f FORKS] [-M MODULE_PATH] [--list-tasks]
                        [--list-tags] [--step] [--start-at-task START_AT_TASK]
                        playbook [playbook ...]
ansible-playbook: error: unrecognized arguments: --sudo

usage: ansible-playbook [-h] [--version] [-v] [--private-key PRIVATE_KEY_FILE]
                        [-u REMOTE_USER] [-c CONNECTION] [-T TIMEOUT]
                        [--ssh-common-args SSH_COMMON_ARGS]
                        [--sftp-extra-args SFTP_EXTRA_ARGS]
                        [--scp-extra-args SCP_EXTRA_ARGS]
                        [--ssh-extra-args SSH_EXTRA_ARGS]
                        [-k | --connection-password-file CONNECTION_PASSWORD_FILE]
                        [--force-handlers] [--flush-cache] [-b]
                        [--become-method BECOME_METHOD]
                        [--become-user BECOME_USER]
                        [-K | --become-password-file BECOME_PASSWORD_FILE]
                        [-t TAGS] [--skip-tags SKIP_TAGS] [-C]
                        [--syntax-check] [-D] [-i INVENTORY] [--list-hosts]
                        [-l SUBSET] [-e EXTRA_VARS] [--vault-id VAULT_IDS]
                        [--ask-vault-password | --vault-password-file VAULT_PASSWORD_FILES]
                        [-f FORKS] [-M MODULE_PATH] [--list-tasks]
                        [--list-tags] [--step] [--start-at-task START_AT_TASK]
                        playbook [playbook ...]

Runs Ansible playbooks, executing the defined tasks on the targeted hosts.

positional arguments:
  playbook              Playbook(s)

optional arguments:
  --ask-vault-password, --ask-vault-pass
                        ask for vault password
  --become-password-file BECOME_PASSWORD_FILE, --become-pass-file BECOME_PASSWORD_FILE
                        Become password file
  --connection-password-file CONNECTION_PASSWORD_FILE, --conn-pass-file CONNECTION_PASSWORD_FILE
                        Connection password file
  --flush-cache         clear the fact cache for every host in inventory
  --force-handlers      run handlers even if a task fails
  --list-hosts          outputs a list of matching hosts; does not execute
                        anything else
  --list-tags           list all available tags
  --list-tasks          list all tasks that would be executed
  --skip-tags SKIP_TAGS
                        only run plays and tasks whose tags do not match these
                        values
  --start-at-task START_AT_TASK
                        start the playbook at the task matching this name
  --step                one-step-at-a-time: confirm each task before running
  --syntax-check        perform a syntax check on the playbook, but do not
                        execute it
  --vault-id VAULT_IDS  the vault identity to use
  --vault-password-file VAULT_PASSWORD_FILES, --vault-pass-file VAULT_PASSWORD_FILES
                        vault password file
  --version             show program's version number, config file location,
                        configured module search path, module location,
                        executable location and exit
  -C, --check           don't make any changes; instead, try to predict some
                        of the changes that may occur
  -D, --diff            when changing (small) files and templates, show the
                        differences in those files; works great with --check
  -K, --ask-become-pass
                        ask for privilege escalation password
  -M MODULE_PATH, --module-path MODULE_PATH
                        prepend colon-separated path(s) to module library (def
                        ault=~/.ansible/plugins/modules:/usr/share/ansible/plu
                        gins/modules)
  -e EXTRA_VARS, --extra-vars EXTRA_VARS
                        set additional variables as key=value or YAML/JSON, if
                        filename prepend with @
  -f FORKS, --forks FORKS
                        specify number of parallel processes to use
                        (default=5)
  -h, --help            show this help message and exit
  -i INVENTORY, --inventory INVENTORY, --inventory-file INVENTORY
                        specify inventory host path or comma separated host
                        list. --inventory-file is deprecated
  -k, --ask-pass        ask for connection password
  -l SUBSET, --limit SUBSET
                        further limit selected hosts to an additional pattern
  -t TAGS, --tags TAGS  only run plays and tasks tagged with these values
  -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                        connection debugging)

Connection Options:
  control as whom and how to connect to hosts

  --private-key PRIVATE_KEY_FILE, --key-file PRIVATE_KEY_FILE
                        use this file to authenticate the connection
  --scp-extra-args SCP_EXTRA_ARGS
                        specify extra arguments to pass to scp only (e.g. -l)
  --sftp-extra-args SFTP_EXTRA_ARGS
                        specify extra arguments to pass to sftp only (e.g. -f,
                        -l)
  --ssh-common-args SSH_COMMON_ARGS
                        specify common arguments to pass to sftp/scp/ssh (e.g.
                        ProxyCommand)
  --ssh-extra-args SSH_EXTRA_ARGS
                        specify extra arguments to pass to ssh only (e.g. -R)
  -T TIMEOUT, --timeout TIMEOUT
                        override the connection timeout in seconds
                        (default=10)
  -c CONNECTION, --connection CONNECTION
                        connection type to use (default=smart)
  -u REMOTE_USER, --user REMOTE_USER
                        connect as this user (default=None)

Privilege Escalation Options:
  control how and which user you become as on target hosts

  --become-method BECOME_METHOD
                        privilege escalation method to use (default=sudo), use
                        `ansible-doc -t become -l` to list valid choices.
  --become-user BECOME_USER
                        run operations as this user (default=root)
  -b, --become          run operations with become (does not imply password
                        prompting)
==> k8s-3: An error occurred. The error will be shown after all tasks complete.
An error occurred while executing multiple actions in parallel.
Any errors that occurred are shown below.

An error occurred while executing the action on the 'k8s-3'
machine. Please handle this error then try again:

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
oomichi commented 2 years ago

Succeeded to create vms. Failed to run ansible-playbook command.

by adding --debug option, we can see a lot of debug information like

$ vagrant up --debug
...
==> k8s-3: Please check https://docs.ansible.com/ansible/intro_inventory.html#hosts-and-groups
==> k8s-3: for more information.
 INFO interface: detail: Running ansible-playbook...
 INFO interface: detail:     k8s-3: Running ansible-playbook...
    k8s-3: Running ansible-playbook...
 INFO subprocess: Starting process: ["/home/oomichi/kubespray-venv/bin/ansible-playbook", "--connection=ssh", "--timeout=30", "--limit=all,localhost", "--inventory-file=/home/oomichi/kubespray/.vagrant/provisioners/ansible/inventory", "--sudo", "--tags=facts", "--forks=3", "--flush-cache", "-e ansible_become_pass=vagrant", "cluster.yml"]
...
DEBUG subprocess: stderr: ansible-playbook: error: unrecognized arguments: --sudo

--sudo option seems wrong on ansible-playbook command.

oomichi commented 2 years ago

The command line looks like

$ ansible-playbook --connection=ssh --timeout=30  --limit=all,localhost  \
--inventory-file=/home/oomichi/kubespray/.vagrant/provisioners/ansible/inventory  \
--sudo  --tags=facts  --forks=3  --flush-cache  -e ansible_become_pass=vagrant  cluster.yml
oomichi commented 2 years ago

After versioning up vagrant, different error happens

$ vagrant destroy
The provider 'libvirt' could not be found, but was requested to
back the machine 'k8s-1'. Please use a provider that exists.

Vagrant knows about the following providers: virtualbox, docker, hyperv

I needed to install libvirt plugin of vagrant with

$ vagrant plugin install libvirt

but that causes another conflict issue like

$ vagrant plugin install libvirt
Installing the 'libvirt' plugin. This can take a few minutes...
Vagrant failed to properly resolve required dependencies. These
errors can commonly be caused by misconfigured plugin installations
or transient network issues. The reported error is:

conflicting dependencies ffi (~> 0.6.3) and ffi (= 1.15.4)
  Activated ffi-1.15.4
  which does not match conflicting dependency (~> 0.6.3)

  Conflicting dependency chains:
    ffi (= 1.15.4), 1.15.4 activated

  versus:
    libvirt (> 0), 0.1.0 activated, depends on
    ffi (~> 0.6.3)
oomichi commented 2 years ago

vagrant-libvirt should be instead of libvirt. However an error still happens.

$ vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Building native extensions. This could take a while...
Vagrant failed to install the requested plugin because it depends
on a library which is not currently installed on this system. The
following library is required by the 'vagrant-libvirt' plugin:

  libvirt

Please install the library and then run the command again.

After installing libvirt-dev package like

$ sudo apt install libvirt-dev

an error message is changed like

$ vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Building native extensions. This could take a while...
Vagrant failed to install the requested plugin because development tools
are required for installation but are not currently installed on this
machine. Please install development tools and then try this command
again.

The package build-essential can solve this issue.

$ sudo apt install libvirt-dev build-essential

Then try again

$ vagrant plugin install vagrant-libvirt
Installing the 'vagrant-libvirt' plugin. This can take a few minutes...
Building native extensions. This could take a while...
Fetching fog-libvirt-0.9.0.gem
Fetching vagrant-libvirt-0.7.0.gem
Installed the plugin 'vagrant-libvirt (0.7.0)'!

Succeeded to install vagrant-libvirt and run vagrant command

$ vagrant destroy
    k8s-3: Are you sure you want to destroy the 'k8s-3' VM? [y/N] y
==> k8s-3: Removing domain...
==> k8s-3: Deleting the machine folder
    k8s-2: Are you sure you want to destroy the 'k8s-2' VM? [y/N] y
==> k8s-2: Removing domain...
==> k8s-2: Deleting the machine folder
    k8s-1: Are you sure you want to destroy the 'k8s-1' VM? [y/N] y
==> k8s-1: Removing domain...
==> k8s-1: Deleting the machine folder
oomichi commented 2 years ago

Succeed to run Kubespray from vagrant up!