ansible-tiger-geocoder-playbook icon indicating copy to clipboard operation
ansible-tiger-geocoder-playbook copied to clipboard

initdb: cannot be run as root

Open SunSparc opened this issue 6 years ago • 2 comments

ansible 2.4.3.0 Vagrant 2.0.0 macOS High Sierra 10.13.3

Any idea what might be wrong here? Ansible is getting an error saying that initdb is being run as root. Yet the yml file specifies that is should be run as postgres:

     - name: reconfigure the db with the new data directory
       command: "/usr/lib/postgresql/9.3/bin/initdb -D {{tiger_pg_data_directory}}"
       sudo: yes
       sudo_user: postgres

Here is the full verbose output of the error:

TASK [reconfigure the db with the new data directory] **************************
task path: /Users/jonathan/temp/census-geocoding-ansible/ansible-tiger-geocoder-playbook/provisioning/tigergeocoder.yml:54
Using module file /usr/local/Cellar/ansible/2.4.3.0_4/libexec/lib/python2.7/site-packages/ansible/modules/commands/command.py
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: vagrant
<127.0.0.1> SSH: EXEC ssh -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2200 -o 'IdentityFile="/Users/jonathan/temp/census-geocoding-ansible/ansible-tiger-geocoder-playbook/.vagrant/machines/tiger/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 -o ControlPath=/Users/jonathan/.ansible/cp/17d6e21220 127.0.0.1 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<127.0.0.1> (0, '/home/vagrant\n', 'OpenSSH_7.4p1, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /Users/jonathan/.ssh/config\r\ndebug1: /Users/jonathan/.ssh/config line 1: Applying options for *\r\ndebug3: kex names ok: [[email protected],diffie-hellman-group-exchange-sha256]\r\ndebug1: Reading configuration data /usr/local/etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 44287\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: vagrant
<127.0.0.1> SSH: EXEC ssh -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2200 -o 'IdentityFile="/Users/jonathan/temp/census-geocoding-ansible/ansible-tiger-geocoder-playbook/.vagrant/machines/tiger/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 -o ControlPath=/Users/jonathan/.ansible/cp/17d6e21220 127.0.0.1 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648 `" && echo ansible-tmp-1521738625.49-133799390322648="` echo /home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648 `" ) && sleep 0'"'"''
<127.0.0.1> (0, 'ansible-tmp-1521738625.49-133799390322648=/home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648\n', 'OpenSSH_7.4p1, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /Users/jonathan/.ssh/config\r\ndebug1: /Users/jonathan/.ssh/config line 1: Applying options for *\r\ndebug3: kex names ok: [[email protected],diffie-hellman-group-exchange-sha256]\r\ndebug1: Reading configuration data /usr/local/etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 44287\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<127.0.0.1> PUT /var/folders/nn/h2lq5bl167q5j5b5ns1d7wtw0000gn/T/tmpkkPdiW TO /home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648/command.py
<127.0.0.1> SSH: EXEC sftp -b - -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2200 -o 'IdentityFile="/Users/jonathan/temp/census-geocoding-ansible/ansible-tiger-geocoder-playbook/.vagrant/machines/tiger/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 -o ControlPath=/Users/jonathan/.ansible/cp/17d6e21220 '[127.0.0.1]'
<127.0.0.1> (0, 'sftp> put /var/folders/nn/h2lq5bl167q5j5b5ns1d7wtw0000gn/T/tmpkkPdiW /home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648/command.py\n', 'OpenSSH_7.4p1, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /Users/jonathan/.ssh/config\r\ndebug1: /Users/jonathan/.ssh/config line 1: Applying options for *\r\ndebug3: kex names ok: [[email protected],diffie-hellman-group-exchange-sha256]\r\ndebug1: Reading configuration data /usr/local/etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 44287\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug2: Remote version: 3\r\ndebug2: Server supports extension "[email protected]" revision 1\r\ndebug2: Server supports extension "[email protected]" revision 2\r\ndebug2: Server supports extension "[email protected]" revision 2\r\ndebug2: Server supports extension "[email protected]" revision 1\r\ndebug2: Server supports extension "[email protected]" revision 1\r\ndebug3: Sent message fd 8 T:16 I:1\r\ndebug3: SSH_FXP_REALPATH . -> /home/vagrant size 0\r\ndebug3: Looking up /var/folders/nn/h2lq5bl167q5j5b5ns1d7wtw0000gn/T/tmpkkPdiW\r\ndebug3: Sent message fd 8 T:17 I:2\r\ndebug3: Received stat reply T:101 I:2\r\ndebug1: Couldn\'t stat remote file: No such file or directory\r\ndebug3: Sent message SSH2_FXP_OPEN I:3 P:/home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648/command.py\r\ndebug3: Sent message SSH2_FXP_WRITE I:4 O:0 S:32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 4 32768 bytes at 0\r\ndebug3: Sent message SSH2_FXP_WRITE I:5 O:32768 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:6 O:65536 S:1416\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 32768 bytes at 32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 6 1416 bytes at 65536\r\ndebug3: Sent message SSH2_FXP_CLOSE I:4\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: vagrant
<127.0.0.1> SSH: EXEC ssh -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2200 -o 'IdentityFile="/Users/jonathan/temp/census-geocoding-ansible/ansible-tiger-geocoder-playbook/.vagrant/machines/tiger/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 -o ControlPath=/Users/jonathan/.ansible/cp/17d6e21220 127.0.0.1 '/bin/sh -c '"'"'chmod u+x /home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648/ /home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648/command.py && sleep 0'"'"''
<127.0.0.1> (0, '', 'OpenSSH_7.4p1, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /Users/jonathan/.ssh/config\r\ndebug1: /Users/jonathan/.ssh/config line 1: Applying options for *\r\ndebug3: kex names ok: [[email protected],diffie-hellman-group-exchange-sha256]\r\ndebug1: Reading configuration data /usr/local/etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 44287\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<127.0.0.1> ESTABLISH SSH CONNECTION FOR USER: vagrant
<127.0.0.1> SSH: EXEC ssh -vvv -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o Port=2200 -o 'IdentityFile="/Users/jonathan/temp/census-geocoding-ansible/ansible-tiger-geocoder-playbook/.vagrant/machines/tiger/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=30 -o ControlPath=/Users/jonathan/.ansible/cp/17d6e21220 -tt 127.0.0.1 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-bcmqlhlfthzufwyzudohgnnaetyabnme; /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648/command.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1521738625.49-133799390322648/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''
<127.0.0.1> (0, '\r\n{"changed": true, "end": "2018-03-22 17:10:25.823544", "stdout": "", "cmd": ["/usr/lib/postgresql/9.3/bin/initdb", "-D", "/gisdata/pg"], "failed": true, "delta": "0:00:00.010430", "stderr": "initdb: cannot be run as root\\nPlease log in (using, e.g., \\"su\\") as the (unprivileged) user that will\\nown the server process.", "rc": 1, "invocation": {"module_args": {"warn": true, "executable": null, "_uses_shell": false, "_raw_params": "/usr/lib/postgresql/9.3/bin/initdb -D /gisdata/pg", "removes": null, "creates": null, "chdir": null, "stdin": null}}, "start": "2018-03-22 17:10:25.813114", "msg": "non-zero return code"}\r\n', 'OpenSSH_7.4p1, OpenSSL 1.0.2n  7 Dec 2017\r\ndebug1: Reading configuration data /Users/jonathan/.ssh/config\r\ndebug1: /Users/jonathan/.ssh/config line 1: Applying options for *\r\ndebug3: kex names ok: [[email protected],diffie-hellman-group-exchange-sha256]\r\ndebug1: Reading configuration data /usr/local/etc/ssh/ssh_config\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 44287\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to 127.0.0.1 closed.\r\n')
fatal: [tiger]: FAILED! => {
    "changed": true,
    "cmd": [
        "/usr/lib/postgresql/9.3/bin/initdb",
        "-D",
        "/gisdata/pg"
    ],
    "delta": "0:00:00.010430",
    "end": "2018-03-22 17:10:25.823544",
    "invocation": {
        "module_args": {
            "_raw_params": "/usr/lib/postgresql/9.3/bin/initdb -D /gisdata/pg",
            "_uses_shell": false,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "warn": true
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2018-03-22 17:10:25.813114",
    "stderr": "initdb: cannot be run as root\nPlease log in (using, e.g., \"su\") as the (unprivileged) user that will\nown the server process.",
    "stderr_lines": [
        "initdb: cannot be run as root",
        "Please log in (using, e.g., \"su\") as the (unprivileged) user that will",
        "own the server process."
    ],
    "stdout": "",
    "stdout_lines": []
}
	to retry, use: --limit @/Users/jonathan/temp/census-geocoding-ansible/ansible-tiger-geocoder-playbook/provisioning/tigergeocoder.retry

PLAY RECAP *********************************************************************
tiger                      : ok=10   changed=8    unreachable=0    failed=1

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

SunSparc avatar Mar 22 '18 17:03 SunSparc

Hello @SunSparc,

It looks like you may need to add become: true to that statement.

(See: http://docs.ansible.com/ansible/latest/user_guide/become.html)

Let us know if it works, and PRs are definitely welcome!

You should also know that this project is a few years old and we are no longer officially supporting it. I am going to add a banner to that effect to the README.md to let others know this.

jak2030 avatar Mar 27 '18 15:03 jak2030

It looks like you are correct. I updated the tigergeocoder.yml file with this:

    - name: reconfigure the db with the new data directory
      command: "/usr/lib/postgresql/9.3/bin/initdb -D {{tiger_pg_data_directory}}"
      become: yes
      become_user: postgres

I have been able to move past that error. I am now onto a new error. If I can get a successful launch I will look at submitting a pull request.

SunSparc avatar Mar 27 '18 23:03 SunSparc