2

In ansible how can we execute fabric commands in Karaf terminal.

Actually in ansible we will execute shell commands, but there are some commands I need to execute with Karaf terminal. Is there any possibility to do.

in generic, how to open other terminal other than shell using ansible playbook

sasi
  • 4,192
  • 4
  • 28
  • 47

1 Answers1

1

Karaf exposes sshd server, you can use it to call commands from Ansible.

inventory:

test ansible_host=192.168.0.15
test-karaf ansible_host=127.0.0.1 ansible_port=8101 ansible_user=karafuser ansible_password=karafpassword ansible_ssh_common_args="-o ProxyCommand='ssh 192.168.0.15 -W %h:%p'"

playbook:

- hosts: test
  gather_facts: no
  tasks:
    - shell: ps aux | grep [b]in/karaf
    - raw: system:version
      delegate_to: test-karaf

This will grep for karaf process on test host and execute system:version command inside karaf shell on that host.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Thanks for the response Suvorov, sorry for the late reply. Am new to this anisble stuff, we dont have access to configure hosts in a file, How to configure ansible_host, ansible_port from ansible.. etc. – sasi Oct 10 '17 at 05:49
  • no sure what you mean by "how to configure from ansible"... you can set this variables via inventory, host vars, group vars. – Konstantin Suvorov Oct 10 '17 at 05:59
  • I mean in yml file Suvorov, we don't have access to inventory file to configure the hosts. – sasi Oct 10 '17 at 08:47
  • You can dynamically add hosts with [add_host](http://docs.ansible.com/ansible/latest/add_host_module.html) module with all required parameters. – Konstantin Suvorov Oct 10 '17 at 09:18