0

I am trying to run a simple query on many servers. I know 100% that the file and directory in question exist.

I can do simple commands, such as ls, pwd, whoami, etc, and I can run the sqlite command on the remote host itself.

The playbook task:

- name: Do a test SELECT statement
  become: yes
  become_user: root
  command: sqlite3 /usr/local/share/sqlite/dbfile.sqlite3 "SELECT * FROM db WHERE hostname="{{ db_server_prompt }}""
  register: query_result

- debug: var=query_result.stdout_lines

The error I'm receiving is "msg": "[Errno 2] No such file or directory: b'sqlite3'",.

Is there something wrong with my syntax? Why is it telling me there's "No such file or directory" when using the sqlite3 command? I've tried the absolute path to the executable (/usr/bin/sqlite3), but I get the same error.

Update I tried to use chdir as an argument per this answer, but I get Unable to change directory before execution. I also tried the absolute path to sqlite with /usr/bin/sqlite3. None of these things are working.

DevOpsSauce
  • 288
  • 4
  • 13

1 Answers1

0

You may have a look into Whats the difference between ansible raw, shell and command? and try the following

- name: Do a test SELECT statement
  become: yes
  become_user: root
  shell:
    cmd: /usr/bin/sqlite3 /usr/local/share/sqlite/dbfile.sqlite3 "SELECT * FROM db WHERE hostname={{ db_server_prompt }}"
  register: query_result

- name: Show query result
  debug: 
    var: query_result.stdout_lines
U880D
  • 597
  • 7
  • 17
  • 1
    I would've never thought to put `cmd` with the `shell` module. After adding some double quotes around the `SELECT` and single quotes around the `db_server_prompt` variable, it worked! I'll accept your answer. – DevOpsSauce Dec 16 '21 at 14:15