The following command fails most likely because it fails to interpolate the shell variable packdir
- name: archive_artifacts.yml --> Clear git history from packs directories
command: 'for packdir in {{ packs_dir }}/*; do rm -rf {{ packs_dir }}/"${packdir}"/.git; done'
args:
chdir: "{{ temp_build_directory }}"
packs_dir
is a variable in the defaults/main.yml
of the specific role:
packs_dir: "packs"
Is there a way of having the command module substituting both ansible
and shell
variables?
Is there a way of having the command module substituting both ansible and shell variables?
Yes. Make sure the shell variable is present in the environment of the host, user and shell you run the command in.
- hosts: localhost
vars:
env_variable: SHELL
tasks:
- command: "echo ${{ env_variable }}"
register: result
- debug: msg="{{ result.stdout }}"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.