Desidero creare un utente del database per il mio script di installazione del fabric ma createuser ha l'immissione della password interattiva e cuciture che non gradiscono il fabric.Come creare un utente postgresql con fabric
18
A
risposta
8
Basta utilizzare SQL semplice per creare un nuovo utente:
CREATE ROLE user_name WITH ENCRYPTED PASSWORD 'your password';
33
Per estendere la risposta con un esempio in tessuto ...
# In fabfile.py
def create_database():
"""Creates role and database"""
db_user = get_user() # define these
db_pass = get_pass()
db_name = get_db_name()
sudo('psql -c "CREATE USER %s WITH NOCREATEDB NOCREATEUSER " \
"ENCRYPTED PASSWORD E\'%s\'"' % (db_user, db_pass), user='postgres')
sudo('psql -c "CREATE DATABASE %s WITH OWNER %s"' % (
db_name, db_user), user='postgres')
+0
Impressionante, molte grazie –
+1
Upwote. Ma in realtà intendevi la tabella in 'db_table = get_table()'? Sembra che tu intenda un nome di database. –
0
Questo è probabilmente di qualche utilità, senza dover scrivere il possedere moduli o potresti usarlo come riferimento.
from fabtools import require
require.postgres.create_db ???
Problemi correlati
- 1. Cambiare utente in Fabric
- 2. Ansible: creare un utente con privilegi sudo
- 3. passare a un altro utente utilizzando il fabric
- 4. Come creare un utente in Django?
- 5. Come creare un controllo utente con angoli arrotondati?
- 6. Come possiamo creare un utente con Firebase Auth in node.js?
- 7. Generazione della password utente postgresql
- 8. Come creare un utente predefinito su meteora?
- 9. Come creare un utente in MongoDB v3.0.5
- 10. Come creare un utente in MongoDB
- 11. PostgreSQL: Esecuzione di procedure Python memorizzato come un normale utente
- 12. Come passare le opzioni SSH con Fabric?
- 13. ACL loopback: creare un utente con un ruolo
- 14. Tentativo di creare un accesso utente per Clojure/Korma/PostgreSQL sito
- 15. Come creare una sequenza partizionata di PostgreSQL?
- 16. Gestione dei guasti con Fabric
- 17. Accesso alla cronologia utente di Twitter tramite Fabric SDK iOS
- 18. Utilizzando LocalDB con Service Fabric
- 19. Postgres su Docker. Come posso creare un database e un utente?
- 20. Rails 3.1. Creare un utente in console con password sicura
- 21. Come creare un controller XY come l'interfaccia utente in WPF
- 22. MySQL: creare un utente con diritti solo per specifici db
- 23. Come ottenere il contenuto di un file remoto senza un file temporaneo locale con fabric
- 24. Fabric - sudo -u
- 25. Posso utilizzare Fabric per eseguire comandi di shell interattivi?
- 26. using flask-login con postgresql
- 27. Come creare app native C++ con interfaccia utente HTML/CSS?
- 28. Come creare utente in MongoDB con finestra mobile-compongo
- 29. Come creare profili utente con PHP e MySQL
- 30. Postgresql - limite di connessione per utente
Come posso inviare questo SQL a Postgres in una battuta? – user320080
Connettersi con il client psql e inviare la query. http://www.postgresql.org/docs/8.4/interactive/app-psql.html –