1

I am setting up ansible to install a DB2 on a linux server. Everything is working except in the last step I need to run:

db2 update database manager configuration using svcename db2c_db2inst1

However, I cannot seem to run that as a unprivileged user (I can run it as db2isnt1 user from cmd line and it works). The task I am using looks like this:

  tasks:
    - name: setup svcename db2c_db2inst1
      remote_user: db2inst1
      shell: db2 update database manager configuration using svcename db2c_db2inst1

but I get the following error:

TASK [setup svcename db2c_db2inst1] ******************************************** fatal: [db2ansible]: FAILED! => {"changed": true, "cmd": "db2 update database manager configuration using svcename db2c_db2inst1", "delta": "0:00:00.003631", "end": "2017-02-13 16:39:38.301753", "failed": true, "rc": 127, "start": "2017-02-13 16:39:38.298122", "stderr": "/bin/sh: 1: db2: not found", "stdout": "", "stdout_lines": [], "warnings": []}

Any suggestions?

Thank you.

Warren.

warhansen
  • 81
  • 1
  • 7

3 Answers3

2

Modify your last task like this:

tasks:
    - name: setup svcename db2c_db2inst1
      shell: db2 update database manager configuration using svcename db2c_db2inst1
      become: yes
      become_user: db2inst1

This will really execute the db2 command with db2inst1 user, which has the db2 executable in it's $PATH

13dimitar
  • 2,508
  • 1
  • 13
  • 15
  • If I run it as you suggested I get prompted for 2 passwords, the first one is ssh password and the second one sudo password. I get errors if I enter the passwords correctly and if I enter the db2inst1 password both times. – warhansen Feb 13 '17 at 14:52
  • 1
    @warhansen You really shouldn't be using password-enabled SSH. Use keys. – EEAA Feb 13 '17 at 14:53
  • I have a ssh authorized_keys to log in but the still does not allow me to run commands on Ubuntu like it does on centos – warhansen Feb 13 '17 at 14:56
  • You're confusing two things: ssh authentication and sudo. Ensure configuration parity between CentOS and Ubuntu and you won't have this issue. – EEAA Feb 13 '17 at 15:02
  • The sftp subsystems in ubuntu and centos are different I think, so he has to watch for that - they are in different locations. – 13dimitar Feb 13 '17 at 15:11
  • Hi, So I got the command using: - name: setup svcename db2c_db2inst1 shell: sudo -H -u db2inst1 bash -c '/home/db2inst1/sqllib/bin/db2 update database manager configuration using svcename db2c_db2inst1'$ logging in as a sudoer user. So basically logging in as a sudo user and running a command from there as different user. A bit of a workaround but it works. – warhansen Feb 14 '17 at 08:11
  • Instead of `sudo..` in the shell module you should youse `become: yes`. People have created modules and features for us - use them. – 13dimitar Feb 14 '17 at 08:15
1

Give the full path to your db2 binary.

EEAA
  • 109,363
  • 18
  • 175
  • 245
  • This seems to make sense: I tried: tasks: - name: setup svcename db2c_db2inst1 shell: /home/db2inst1/sqllib update database manager configuration using svcename db2c_db2inst1 remote_user: db2inst1 ------- Now I get permission denied – warhansen Feb 13 '17 at 15:01
0

You would must load "db2profile" previously:

tasks:
  - name: setup svcename db2c_db2inst1
    shell: "$INSTANCEPATH/sqllib/db2profile; db2 update database manager configuration using svcename db2c_db2inst1"
    become: yes
    become_user: db2inst1

When $INSTANCEPATH is the path's home of db2 instance (e.g., /home/db2inst1)

alexander.polomodov
  • 1,068
  • 3
  • 10
  • 14
Tomy
  • 1