Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tSkY1-001Elf-Q2 for pgsql-general@arkaria.postgresql.org; Tue, 31 Dec 2024 22:17:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tSkY1-005VAa-2P for pgsql-general@arkaria.postgresql.org; Tue, 31 Dec 2024 22:17:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tSkY0-005VAS-Jo for pgsql-general@lists.postgresql.org; Tue, 31 Dec 2024 22:17:08 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tSkXx-002ZN6-7O for pgsql-general@lists.postgresql.org; Tue, 31 Dec 2024 22:17:07 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-aa6c0d1833eso2122024166b.1 for ; Tue, 31 Dec 2024 14:17:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wars-nicht.de; s=google; t=1735683423; x=1736288223; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Cf8BtGyCGoPDQ/EVGWx9nomEouFsnxCNC9G1vcbPcMM=; b=Qj2ive80n4XR8E+JtBPO0ZUL1/oTNSCT44d98NLY0F1CJ0YtrTWrMlz9rZqfsXDKin B9qVOuJ56hrPQBXvyb5+bircKQlYjKvA9hRq0eWdqUN11nvvdtZ48jRbnN76lB+olsSa WZp5n2f1JVkkyYEU2gRKIICShDGp86WHfdQ/wooVOc4QmNFTTqUyXpwqrQmaKubOiDVJ +CgAjXCR+6E8XdgOK7ol+WVckkxkuDoS7dnw7CPUQNjnw/iYtmYdqtxFD2I/g77QvQBD ccescQfQU2i6TgnA6CpM4UGHfunRjVH3DDYHH66O8u7UsLBOY4dk7LdmjMMFPgxS+V7e cgNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735683423; x=1736288223; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Cf8BtGyCGoPDQ/EVGWx9nomEouFsnxCNC9G1vcbPcMM=; b=RBQXZLiKS03wo/nQWXEfRjyzCV6RGa+gunD8sDMWLBeclnGBmtSQ9vwZIpTrbcvkMb ww06eO77G0jdPissik+9oXmKnBRpm5CjFyqeVOhuedU82Fu3/68JbVKJ24fMoBRIJHYf YVpJlaWwDEB8BTAF6QoztLeMFgVgQ+ZxBf+lbG7eMrYIF3Kf4j67D9Qc/Em6G8UbG4mp 7yWzVYB7PpT2MMRLzCoZUo+biKG3CiP/3qPbuPVxCRD9WEm0T4+IE69ILE1WcA5MHqYl lQ+A0QnEnKs0IhKoJ/8HrsXRTL1nGWiJPg4+MKvH+ZJqe5gP+XBdqocsS+CM9n5//IQx H4Nw== X-Gm-Message-State: AOJu0YwBYJDlN2EG4tozL1/bBA8kxqCEIR76AyB5VZBTkzK8qJO4ku4z sAv3B2iQMEMs3rXAUhS7QkhVvEd7zZBaQb3O0o19s07S99nMEXOmI5T149coPTObr2bFbLkp7bK lD8KX3/7CBwp4eOalc/pquFAcFl8FMOMOJx8suK+C5h19bA3fHlM= X-Gm-Gg: ASbGnct8Y2RaY9FcXaiUFFCbDbOMG2Szk7o6U4FNcO8toCJiRhesE6gqirrdTvTXTLs PyRNIH2xP53Uo15sRokURHHBGTERCqdF/sAU= X-Google-Smtp-Source: AGHT+IG0EqLzAilHvVe05Hk3Thv+pXQxn9j3pTiEUcVmURZSRhvOcddb+P0DQDytw2Xuf5zrmoxbkxQno/DIL0lyBPY= X-Received: by 2002:a17:907:6c10:b0:aae:85ad:6357 with SMTP id a640c23a62f3a-aae85ad6586mr2840186066b.53.1735683423188; Tue, 31 Dec 2024 14:17:03 -0800 (PST) MIME-Version: 1.0 References: <75b177a0f2627519419009a2134fe050f3f623cb.camel@ageofdream.com> In-Reply-To: <75b177a0f2627519419009a2134fe050f3f623cb.camel@ageofdream.com> From: "Andreas 'ads' Scherbaum" Date: Tue, 31 Dec 2024 23:16:46 +0100 Message-ID: Subject: Re: Initial Postgres admin account setup using Ansible? To: Nick Cc: pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000e1d9cc062a984990" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e1d9cc062a984990 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, On Tue, Dec 31, 2024 at 10:32=E2=80=AFPM Nick wrote= : > > I'm trying to create an Ansible playbook that sets up and manages > Postgres on Debian 12. > > I'm having issues with the default username/login structure, and could > use some help. > > I'm installing the `postgresql` package via apt, and Debian creates a > `postgres` system account that has a locked password. > > I can login to Postgres manually by first becoming root then running > `sudo -u postgres psql` as root. But when the Ansible user (which has > passwordless sudo) tries to run `sudo -u postgres psql`, I get: > > "Sorry, user Ansible is not allowed to execute '/usr/bin/psql' as > postgres on example.com." > > This is likely because the postgres POSIX account has a locked > password, so only root can become postgres. Other users with sudo > permissions can't become a locked account. > > So I **could** unlock the `postgres` POSIX account, but I understand > that this account is locked for a reason. > > The goal is to have Ansible manage the creation of databases and roles > in the Postgres database. > > So I need to create an account in Postgres that Ansible can use as the > super user. I would like to do this in a way that doesn't require me to > manually login to the server, become root, become postgres as root, > then manually create an Ansible role. > > What is the proper (secure) way to let the Ansible POSIX user manage > postgres? It seems there should be a fully automated way to bootstrap > an Ansible user for `postgres`. > Can you please provide an example of the task(s) which fail? If you have passwordless "sudo" configured tor the user running Ansible, this works: - name: Ping PostgreSQL postgresql_ping: db: postgres login_unix_socket: "/var/run/postgresql" login_user: postgres become: yes become_user: postgres More examples and details: https://andreas.scherbaum.la/writings/Managing_PostgreSQL_with_Ansible_-_Pe= rcona_Live_2022.pdf Regards, --=20 Andreas 'ads' Scherbaum German PostgreSQL User Group European PostgreSQL User Group - Board of Directors Volunteer Regional Contact, Germany - PostgreSQL Project --000000000000e1d9cc062a984990 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hello,

On Tue, Dec 31, 2024 at 10:32=E2=80=AFPM Nick <lists2@ageofdream.com> wrote:

I'm trying to create an Ansible playbook that sets up and manages
Postgres on Debian 12.

I'm having issues with the default username/login structure, and could<= br> use some help.

I'm installing the `postgresql` package via apt, and Debian creates a `postgres` system account that has a locked password.

I can login to Postgres manually by first becoming root then running
`sudo -u postgres psql` as root. But when the Ansible user (which has
passwordless sudo) tries to run `sudo -u postgres psql`, I get:

"Sorry, user Ansible is not allowed to execute '/usr/bin/psql'= as
postgres on example.com."

This is likely because the postgres POSIX account has a locked
password, so only root can become postgres. Other users with sudo
permissions can't become a locked account.

So I **could** unlock the `postgres` POSIX account, but I understand
that this account is locked for a reason.

The goal is to have Ansible manage the creation of databases and roles
in the Postgres database.

So I need to create an account in Postgres that Ansible can use as the
super user. I would like to do this in a way that doesn't require me to=
manually login to the server, become root, become postgres as root,
then manually create an Ansible role.

What is the proper (secure) way to let the Ansible POSIX user manage
postgres? It seems there should be a fully automated way to bootstrap
an Ansible user for `postgres`.

Can you= please provide an example of the task(s) which fail?
If you = have passwordless "sudo" configured tor the user running Ansible,=
this works:

- name: Ping PostgreSQL
=C2=A0 postgresql_ping:
=C2=A0 db:= postgres
=C2=A0 login_unix_socket: "/var/run/postgresql"
= =C2=A0 login_user: postgres
=C2=A0 become: yes
=C2=A0 become_user: po= stgres
=C2=A0
More examples and details:
https://andreas.scherbaum.la/writings/Ma= naging_PostgreSQL_with_Ansible_-_Percona_Live_2022.pdf
=

Regards,

--
<= span style=3D"white-space:pre"> Andreas 'ads' Sche= rbaum
German PostgreSQL User Group
European PostgreSQL User Group - B= oard of Directors
Volunteer Regional Contact, Germany - PostgreSQL Proje= ct
--000000000000e1d9cc062a984990--