Search code examples
ansiblevagrant

Having trouble using Ansible to deploy Quantum Mobile to AWS EC2 Instance. I'm not sure how to configure a setting called "vagrant" or "vagrant-ssh"


Here is the feedback in the shell. I'm not sure how to configure or install this vagrant thing. I couldn't find any clear instructions online. Any help would be appreciated.

  (quantum_env) user@localComputer quantum-mobile % tox -e ansible -- --extra-vars "build_hosts_aws"



...
ansible run-test: commands[0] | ansible-playbook playbook-build.yml --extra-vars build_hosts_aws
[WARNING]: Invalid characters were found in group names but not replaced, use
-vvvv to see details

PLAY [Install ansible prerequisites] *******************************************

TASK [test configuration] ******************************************************
Sunday 14 February 2021  14:00:22 -0500 (0:00:00.040)       0:00:00.040 *******
ok: [vagrant-ssh] =>
  msg: RUNNING PLAYBOOK FOR 'Quantum Mobile' VERSION '20.11.2a'

TASK [testing ansible environment] *********************************************
Sunday 14 February 2021  14:00:22 -0500 (0:00:00.029)       0:00:00.070 *******
ok: [vagrant-ssh] =>
  msg: Connecting to host 'vagrant-ssh' as user 'vagrant'

TASK [Make local dist folder] **************************************************
Sunday 14 February 2021  14:00:22 -0500 (0:00:00.034)       0:00:00.105 *******
ok: [vagrant-ssh]

TASK [marvel-nccr.ansible_prerequisites : update cache] ************************
Sunday 14 February 2021  14:00:23 -0500 (0:00:00.369)       0:00:00.475 *******
fatal: [vagrant-ssh]: UNREACHABLE! => changed=false
  msg: 'Failed to connect to the host via ssh: Can''t open user config file vagrant-ssh: No such file or directory'
  unreachable: true

PLAY RECAP *********************************************************************
vagrant-ssh                : ok=3    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0

Sunday 14 February 2021  14:00:23 -0500 (0:00:00.026)       0:00:00.501 *******
===============================================================================
Make local dist folder -------------------------------------------------- 0.37s
testing ansible environment --------------------------------------------- 0.03s
test configuration ------------------------------------------------------ 0.03s
marvel-nccr.ansible_prerequisites : update cache ------------------------ 0.03s
ERROR: InvocationError for command /Users/user/quantum-mobile/.tox/ansible/bin/ansible-playbook playbook-build.yml --extra-vars build_hosts_aws (exited with code 4)
___________________________________ summary ____________________________________
ERROR:   ansible: commands failed

UPDATE: I was able to install Vagrant from the link but I was not able to correctly install VirtualBox. When I try to do vagrant up I get the following error message

(quantum_env) localhost:quantum-mobile user$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'bento/ubuntu-18.04' version '202012.21.0' is up to date... ==> default: Clearing any previously set network interfaces... There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%... Progress state: NS_ERROR_FAILURE VBoxManage: error: Failed to create the host-only adapter VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface VBoxManage: error: Context: "RTEXITCODE handleCreate(HandlerArg *)" at line 95 of file VBoxManageHostonly.cpp


Solution

  • From the documentation

    Prerequisites & Installation

    Vagrant >= 2.0.1
    VirtualBox >= 6.1.6
    Python >= 3.6
    

    You can install vagrant from here Installing Vagrant and VirtualBox from here

    Once you install vagrant and VirtualBox you can launch the machine on your by

    vagrant up
    

    There is a Vagrantfile in the main repo for ansible-playbooks.

    After that you can simply can configure vagrant-ssh as described in the documentation

    vagrant ssh-config > vagrant-ssh
    tox -e ansible
    

    Depending on how you want to run the ansible-playbook you need to modify few parameters in inventory

    The error you see stems from the following configuration in the inventory

    vagrant-provision:
        # this private network IP will be created by `vagrant up`
        cloud_platform: virtualbox
        ansible_host: 192.168.111.222
        ansible_user: vagrant
    vagrant-ssh:
        # requires first running `vagrant ssh-config > vagrant-ssh`
        cloud_platform: virtualbox
        ansible_host: default
        ansible_ssh_common_args: "-F vagrant-ssh"
        ansible_user: vagrant
    

    If you want to use aws machine you need to update the IP address here.

        # To connect to VMs you should change the host IP and provide an SSH key file
    aws:
        cloud_platform: aws
        ansible_host: 34.227.10.49  # change this
        ansible_ssh_common_args: -i ./keys/quantum-mobile.pem -o StrictHostKeyChecking=no
        ansible_user: ubuntu
        vm_headless: true
        add_user_public_key: "{{ lookup('file', './keys/user-key.pub') }}
    

    For launching the instance you can refer here

    Seems like the like the link to launch instance is broken.

    You can follow this to Launch an Amazon EC2 Instance