How to pass variable from shell to Ansible playbooks -
i have deploy.sh script call trigger deploy tasks ansible. in simplified form, deploy command triggered deploy.sh
deploy_cmd="ansible-playbook -i hosts/$1 deploy.yml --extra-vars="site=$2 theme=$3""
this fragment of task:
project_pre_build_commands_local:    - path: "{{ project.local_path }}/web/app/themes/{{ theme }}"      cmd: npm install    - path: "{{ project.local_path }}/web/app/themes/{{ theme }}"      cmd: bower install    - path: "{{ project.local_path }}/web/app/themes/{{ theme }}"      cmd: gulp --production   unfortunately shell errors out with:
msg: cannot change directory '/home/ltarasiewicz/dev/bedrock-stack/bedrock-ansible/{# project.local_path #}/web/app/themes/{# theme #}': path not exist
the theme variable i'm passing deploy.sh 'cpkg'. specified directory exists. more so, if define path like: - path: "{{ project.local_path }}/web/app/themes/cpkg"(get rid of {{ theme }} variable), goes - process completes without errors.
i'm confused. appreciate advice.
you have problem quotes in deploy_cmd.
when echo $deploy_cmd in deploy.sh script should see this:
ansible-playbook -i hosts/ deploy.yml --extra-vars=site=   the variable not contain parameters.
to solve problem can use single quotes instead:
deploy_cmd="ansible-playbook -i hosts/$1 deploy.yml --extra-vars='site=$2 theme=$3'"      
Comments
Post a Comment