pyinfra.api.exceptions.PyinfraError : Nested operation called with global arguments
See original GitHub issueDescribe the bug
While using below code and running pyinfra @local deploy.py
command, following exception is raised by pyinfra:
pyinfra.api.exceptions.PyinfraError: Nested operation called with global arguments: ['sudo', 'sudo_user', 'use_sudo_login', 'use_sudo_password', 'preserve_sudo_env', 'su_user', 'use_su_login', 'preserve_su_env', 'su_shell', 'name', 'shell_executable', 'chdir', 'env', 'ignore_errors', 'success_exit_codes', 'timeout', 'get_pty', 'stdin', 'precondition', 'postcondition', 'on_success', 'on_error', 'parallel', 'run_once', 'serial'] (line 821 in ../usr/local/lib/python3.6/dist-packages/pyinfra/operations/server.py)
To Reproduce Steps to reproduce the behavior (include code & usage example):
deploy.py file:
from install_prometheus import install_prometheus
install_prometheus()
install_prometheus.py file:
from pyinfra.api import deploy, DeployError
from pyinfra.operations import files, init, server
@deploy('Install prometheus', data_defaults=None)
def install_prometheus(state, host):
server.user(
name='Create the prometheus user',
user='rajgouravj',
shell='/sbin/bash',
state=state,
host=host,
)
Expected behavior A clear and concise description of what you expected to happen.
The example is derived from [pyinfra-prometheus] (https://github.com/grantstephens/pyinfra-prometheus). It seems global arguments are not supported in Nested operations which has broken server.user and @deploy functions/decorators.
Meta
- Include output of
pyinfra --support
.
--> Support information:
If you are having issues with pyinfra or wish to make feature requests, please
check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
When adding an issue, be sure to include the following:
System: Linux
Platform: Linux-5.4.39-linuxkit-x86_64-with-Ubuntu-18.04-bionic
Release: 5.4.39-linuxkit
Machine: x86_64
pyinfra: v1.3.1
Executable: /usr/local/bin/pyinfra
Python: 3.6.9 (CPython, GCC 8.4.0)
-
How was pyinfra installed (source/pip)? using pip
-
Include pyinfra-debug.log (if one was created) NA
-
Consider including output with
-vv
and--debug
.
Output:
--> Loading config...
--> Loading inventory...
--> Connecting to hosts...
[@local] Connected
--> Preparing operations...
Loading: deploy.py
--> An unexpected exception occurred in: deploy.py:
File "/usr/local/lib/python3.6/dist-packages/pyinfra_cli/util.py", line 52, in exec_file
exec(PYTHON_CODES[filename], data)
File "deploy.py", line 3, in <module>
install_prometheus()
File "/usr/local/lib/python3.6/dist-packages/pyinfra/api/deploy.py", line 118, in decorated_func
func(*args, **kwargs)
File "/pyinfra-root/install_prometheus.py", line 12, in install_prometheus
host=host,
File "/usr/local/lib/python3.6/dist-packages/pyinfra/api/operation.py", line 347, in decorated_func
commands = unroll_generators(func(*actual_args, **actual_kwargs))
File "/usr/local/lib/python3.6/dist-packages/pyinfra/api/util.py", line 180, in unroll_generators
for item in generator:
File "/usr/local/lib/python3.6/dist-packages/pyinfra/operations/server.py", line 821, in user
state=state, host=host,
File "/usr/local/lib/python3.6/dist-packages/pyinfra/api/operation.py", line 189, in decorated_func
).format(global_kwarg_keys, get_call_location()))
pyinfra.api.exceptions.PyinfraError: Nested operation called with global arguments: ['sudo', 'sudo_user', 'use_sudo_login', 'use_sudo_password', 'preserve_sudo_env', 'su_user', 'use_su_login', 'preserve_su_env', 'su_shell', 'name', 'shell_executable', 'chdir', 'env', 'ignore_errors', 'success_exit_codes', 'timeout', 'get_pty', 'stdin', 'precondition', 'postcondition', 'on_success', 'on_error', 'parallel', 'run_once', 'serial'] (line 821 in ../usr/local/lib/python3.6/dist-packages/pyinfra/operations/server.py)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to use the pyinfra.api.exceptions.PyinfraError function in ...
class OperationError(PyinfraError): ''' Exception raised during fact gathering staging if an operation is unable to generate output/change state. ''' class ...
Read more >Using Operations — pyinfra documentation
Global arguments are covered in detail here: Global Arguments. ... Nested operations are called during the execution phase within a callback function passed ......
Read more >Dive into Pyinfra - mmap.page
Operations #. Global Arguments #. sudo : execute with sudo; env : dictionary of environment variables to set; ignore_errors ...
Read more >Permit argparse global flags after subcommand - Stack Overflow
This is a perfect use case for parents argparse feature: Sometimes, several parsers share a common set of arguments. Rather than repeating the...
Read more >pyinfra - PyPI
from pyinfra.operations import apt apt.packages( name="Ensure iftop is ... See how to use inventory & data, global arguments and the CLI or check...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
awesome! Thank you for quick fix!
Now released in
v1.3.2
!