Score:0

Cannot execute sqlite statement with Ansible command module - [Errno 2] No such file or directory: b'sqlite3'"

jp flag

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.

Score:0
ph flag

I had a similar issue but with ifquery : ifquery -l", "msg": "[Errno 2] No such file or directory.

The thing is that ifquery needs root permissions, and I was running my playbook without requesting root permissions.

To run the playbook as root, simply use the -b option with ansible-playbook, or add become=True in your ansible.cfg.

Score:0
ca flag

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
DevOpsSauce avatar
jp flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.