Closed int0x80 closed 3 years ago
Resolved. My approach was incorrect with inventory.py
.
my_hosts = ['@vagrant/default'] # define a group as a list of hosts
Running:
$ pyinfra -vv --debug inventory.py deploy.py
[pyinfra_cli.main] Checking potential directory:
[pyinfra_cli.main] Deploy directory remains as cwd
--> Loading config...
--> Loading inventory...
[pyinfra_cli.inventory] Creating fake inventory...
Getting Vagrant config...
localhost: >>> vagrant status --machine-readable
[pyinfra.api.connectors.util] --> Waiting for exit status...
[pyinfra.api.connectors.util] --> Command exit status: 0
[pyinfra.api.connectors.vagrant] Loading SSH config for default
localhost: >>> vagrant ssh-config default
[pyinfra.api.connectors.util] --> Waiting for exit status...
[pyinfra.api.connectors.util] --> Command exit status: 0
[pyinfra.api.connectors.vagrant] Got Vagrant SSH info:
['Host default', 'HostName 127.0.0.1', 'User vagrant', 'Port 2231', 'UserKnownHostsFile /dev/null', 'StrictHostKeyChecking no', 'PasswordAuthentication no', 'IdentityFile /private/tmp/lol/.vagrant/machines/default/vmware_desktop/private_key', 'IdentitiesOnly yes', 'LogLevel FATAL', '']
[pyinfra.api.connectors.vagrant] Got Vagrant SSH info:
['Host default', 'HostName 127.0.0.1', 'User vagrant', 'Port 2231', 'UserKnownHostsFile /dev/null', 'StrictHostKeyChecking no', 'PasswordAuthentication no', 'IdentityFile /private/tmp/lol/.vagrant/machines/default/vmware_desktop/private_key', 'IdentitiesOnly yes', 'LogLevel FATAL', '']
--> Connecting to hosts...
[pyinfra.api.connectors.ssh] Connecting to: @vagrant/default ({'allow_agent': False, 'look_for_keys': False, 'hostname': '127.0.0.1', 'username': 'vagrant', 'port': 2231, 'timeout': 10, 'pkey': <paramiko.rsakey.RSAKey object at 0x10742c1c0>})
[@vagrant/default] Connected
[pyinfra.api.state] Activating host: @vagrant/default
--> Preparing operations...
Loading: deploy.py
[pyinfra.api.operation] Adding operation, {'Run an ad-hoc command'}, opOrder=(3,), opHash=08743582456b52abe1182f5a5a3e12b457ba28b8
[pyinfra.api.operation] Adding operation, {'Ensure the apt packages are installed'}, opOrder=(9,), opHash=c11b7766912fe844d36569f005f08e2e2799e6c3
[pyinfra.api.facts] Getting fact: deb_packages () (ensure_hosts: (Host(@vagrant/default),))
[pyinfra.api.connectors.ssh] Running command on @vagrant/default: (pty=False) sudo -H -n sh -c '! command -v dpkg >/dev/null || dpkg -l'
[@vagrant/default] >>> sudo -H -n sh -c '! command -v dpkg >/dev/null || dpkg -l'
[pyinfra.api.connectors.ssh] Waiting for exit status...
[pyinfra.api.connectors.ssh] Command exit status: 0
Loaded fact deb_packages ()
[@vagrant/default] noop: package git is installed (1:2.25.1-1ubuntu3.1)
[@vagrant/default] noop: package tmux is installed (3.0a-2ubuntu0.3)
[@vagrant/default] noop: package vim is installed (2:8.1.2269-1ubuntu5)
[@vagrant/default] Ready: deploy.py
--> Proposed changes:
Groups: inventory / @vagrant / my_hosts
[@vagrant/default] Operations: 2 Commands: 2
--> Beginning operation run...
--> Starting operation: Run an ad-hoc command
[pyinfra.api.operations] Starting operation Run an ad-hoc command on @vagrant/default
[pyinfra.api.connectors.ssh] Running command on @vagrant/default: (pty=None) sh -c id
[@vagrant/default] >>> sh -c id
[pyinfra.api.connectors.ssh] Waiting for exit status...
[pyinfra.api.connectors.ssh] Command exit status: 0
[@vagrant/default] Success
--> Starting operation: Ensure the apt packages are installed
[pyinfra.api.operations] Starting operation Ensure the apt packages are installed on @vagrant/default
[pyinfra.api.connectors.ssh] Running command on @vagrant/default: (pty=None) sudo -H -n sh -c 'DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install i3'
[@vagrant/default] >>> sudo -H -n sh -c 'DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install i3'
[pyinfra.api.connectors.ssh] Waiting for exit status...
[pyinfra.api.connectors.ssh] Command exit status: 0
[@vagrant/default] Success
--> Results:
Groups: inventory / @vagrant / my_hosts
[@vagrant/default] Successful: 2 Errors: 0 Commands: 2/2
@int0x80 thank you for raising this - the error in the first instance was definitely not helpful. I've just pushed/released an improvement for that in https://github.com/Fizzadar/pyinfra/commit/aed9f111dc80cd0244f285c45e69f6a677c32d37 / v1.4.13.
Describe the bug
pyinfra
cannot find a running Vagrant instance.To Reproduce
Steps to reproduce the behavior (include code & usage example):
Vagrantfile:
inventory.py:
deploy.py:
Running:
Expected behavior
Expected
pyinfra
to runid
on the VM and install packages and dependencies viaapt
:git
,i3
,tmux
,vim
.Meta
pyinfra --support
.-vv
and--debug
.Verifying: