Calling a remote bash function via an accessible

Is it possible to call a remote function defined in bash (for example, added to one of the scripts that are stored in the /etc/profile.d file) through an available ad-hoc command (using shell, command modules?)

For example, I have the following function that allows me to see the status of apt history:

function apt-history(){
  case "$1" in
    install)
          cat /var/log/dpkg.log | grep 'install '
          ;;
    upgrade|remove)
          cat /var/log/dpkg.log | grep $1
          ;;
    rollback)
          cat /var/log/dpkg.log | grep upgrade | \
              grep "$2" -A10000000 | \
              grep "$3" -B10000000 | \
              awk '{print $4"="$5}'
          ;;
    *)
          cat /var/log/dpkg.log
          ;;
  esac
}

      

Is it possible to call this function directly through the function name from one of the existing existing modules using a special command? I know that it would be possible to create a new script and call it directly remotely, but this I don't want to achieve this. Any suggestions are appreciated.

+3


source to share


1 answer


You need to instantiate bash on the remote using command or wrapper module like this:

ansible localhost -m command -a 'bash -lc apt-history'

      



This is a common trick if you need to tweak environment variables.

+2


source







All Articles