OhNobleNarwhal
OhNobleNarwhal

Reputation: 1

Running terminal command via Ansible playbook

I'm having, what appears to be, a common issue of running shell/terminal commands via an ansible playbook.

If I were to go onto on of my remote machines and type the command on a fresh terminal window, it works, however attempting to do the same via a playbook is having directory issues.

This is essentially the command, but some of it changed a little for privacy, but its essentially an authenticator...

authenticator authenticate user userkeytab

If I try to just run it as shell, I get an error that the authenticator command cant be found in /bin/sh, so I attempted to use chdir to run the command at the default window, (/Users/username).

Here is roughly, the playbook, with one of my failed attempts... I just don’t know what chdir I should be using...

- hosts: all
  tasks:
  - name: Reauthenticate login
    shell: authenticator authenticate user userkeytab
    args:
      chdir: ~/

ive also tried usr/local/bin.... any thoughts?

Upvotes: 0

Views: 998

Answers (1)

einonsy
einonsy

Reputation: 129

can you try with the 'command' module, example below:

- name: Change the working directory to somedir/ and run the command as db_owner if /path/to/database does not exist.
  command: /usr/bin/make_database.sh db_user db_name
  become: yes
  become_user: db_owner
  args:
    chdir: somedir/
    creates: /path/to/database

Resource:

https://docs.ansible.com/ansible/latest/modules/command_module.html

Upvotes: 0

Related Questions