Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke context doesn't work for Group.run #1861

Open
rahul003 opened this issue Aug 24, 2018 · 2 comments
Open

Invoke context doesn't work for Group.run #1861

rahul003 opened this issue Aug 24, 2018 · 2 comments

Comments

@rahul003
Copy link

c = Context()
with c.cd(dir):
    print(c.cwd)
    self.group.run('pwd', **kwargs, hide=hide)

c.cwd shows correct directory but group.run doesn't show that path. How do I get around this?

@stevenhair
Copy link

I don't think that it's possible to use contexts with groups right now. For the moment, my workaround is to just loop through my hosts and create a connection for each one.

Naturally, this isn't the best solution. It's a bit messy, verbose, and doesn't really work if you need a ThreadingGroup.

for host in ['host1', 'host2', 'host3]:
    with Connection(host) as c:
        with c.cd('/some/dir'):
            c.run('pwd')

@Eidansoft
Copy link

Eidansoft commented Aug 31, 2022

I face this issue, Contexts not working at Groups. The work-around I used is concatenate the cd with my command inside a /bin/bash -c ... line (in order to make the special chars like && been not escaped from the sudo):
conn_group.sudo(f'/bin/bash -c "cd {working_path} && find {working_path} -name \'*.pyc\' -delete"', user=user)
I reckon a problem is that current latest doc make you think that Context work on Groups:
As with Connection, Group objects may be used as context managers, which will automatically close the object on block exit. as you can read at https://docs.fabfile.org/en/stable/api/group.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants