question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pyinfra tries to collect postgresql fact on wrong host

See original GitHub issue

Describe the bug

While running postgresql.PostgresqlDatabases fact, pyinfra does not take into consideration postgresql_host conditional logic.

To Reproduce

databases = host.get_fact(postgresql.PostgresqlDatabases, postgresql_user="admin", postgresql_password="admin",
                          postgresql_host="localhost" if host.data.node=="master" else "192.168.56.10")

Here is the error log:

psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
    [192.168.56.11]     Is the server running on that host and accepting TCP/IP connections?

Expected behavior

With the fact collection above, pyinfra would not run the conditional logic for host selection, and default to host as localhost regardless of which server it is running on. Since one of the servers, I am targeting, is running the postgres its host needs to be localhost, while others are not running postgres and thus the host they use to connect to postgres needs to be different (ip in this case). Thus, I would expect that the conditional logic in postgresql_host field is respected when choosing a host to connect to.

Meta

  • Include output of pyinfra --support.
  • How was pyinfra installed (source/pip)? pip
  • Include pyinfra-debug.log (if one was created)
  • Consider including output with -vv and --debug.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
PermanAtayevcommented, Mar 17, 2022

@PermanAtayev my apologies - my workaround actually has exactly the same issue. The fact will always be executed on all hosts. A quick hack for now could be to ignore errors:

host.get_fact(postgresql.PostgresqlDatabases, su_user="postgres", ignore_errors=True)

This should get you going. Alternatively you could try out v2.0.dev0 which should properly resolve this issue. This is an unfortunate gotcha with the way v1 generates operations.

I will check v2.0.dev0 because ignoring errors is not really an option. Thank you 😃

0reactions
Fizzadarcommented, Apr 9, 2022

v2 is now out which should resolve this, please re-open or make a new issue if there are still problems 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Postgresql Facts - pyinfra Documentation
host.get_fact(PostgresqlDatabases, psql_user=None, psql_password=None, psql_host=None, psql_port=None). Returns a dict of PostgreSQL databases and metadata:.
Read more >
Add more patterns/examples for deploys · Issue #200 - GitHub
I would like to see more patterns/examples for deploys. Ansible's docs usually contain a useable snippet as a starting point.
Read more >
psql: error: connection to server at "127.0.0.1", port 5432 failed
Im trying to use PostgreSQL with django and I get that error when running ... server running on that host and accepting TCP/IP...
Read more >
10 Things I Hate About PostgreSQL | by Rick Branson - Medium
10 Things I Hate About PostgreSQL | by Rick Branson | Medium. PostgreSQL performance degrades rapidly with more connections. Credit: brandur.org.
Read more >
Trying Ansible alternatives in python - Bystroushaak's blog
After spending evening by studying Ansible alternatives, I've decided to use pyinfra, and I am quite happy with it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found