Newbee2
Newbee2

Reputation: 219

Execute environment file in ansible

I am trying to setup a playbook which will execute the env file of a service before running the command to stop the service.
Note that stop or start service command will only work after execute that env file.

The command to execute the env file is . ./.env_file_name or ksh .env_file_name

I am not able to execute the file using the above command in command module and shell module.

  1. How to execute the above env file in ansible ?
  2. How to run the stop command after executing the env file ?

Upvotes: 0

Views: 397

Answers (1)

K. Alexander
K. Alexander

Reputation: 47

If env file contains some environment variables that you need to set before running stop, then you can read the file, store results in a variable, then use environment keyword to provide them to the task, that actually stops the service.

Alternatively, you can add multiple commands in shell module at once, like so:

- name: Example for a shell module
  shell:
    cmd: |
      ./.env_file_name
      ./stop.sh (insert command to stop the service here)

Upvotes: 1

Related Questions