I am executing shell commands via Ansible.
Sometimes i don't have the complete foldername. Suppose i have dirname solr4.7.0
.
In shell I can type cd solr*
.
But in ansible I can't do:
chdir=/var/solr*
Is there any workaround?
No. The chdir=
parameter to, e.g., the command
module does not support wildcards.
You could accomplish what you want using a register variable to store the output of the ls
command:
- shell: ls -d solr*
register: dir_name
- command: some_command
args:
chdir: "{{ dir_name.stdout }}"
But this is, frankly, an ugly solution. You're better off just using the actual directory name. If it differs on different hosts, you can use host variables to set it appropriately.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments