2020年12月30日星期三

Ansible if else using shell script

I am using following ansible tasks for triggering certain a task based on user's choice.

This is working:

tasks:    - name: Run python script for generating Repos Report      command: python GetRepos.py -o  -p       register: result    - debug: msg=""      when: choice == "Repos"      - name: Run python script for generating projects Report      command: python Getprojects.py -o  -p       register: result    - debug: msg=""      when: choice == "projects"  

But I want to use a shell script with if else statement to run this in one task as below:

tasks:     - name: run python script       shell: |         if [choice == "repos"]         then         cmd: python GetRepos.py -o  -p           elif [choice == "projects"]         then         cmd: python Getprojects.py -o  -p          fi      register: cmd_output    - debug: msg=""  

But this does not execute the task; it just ends without error.

Is this the right syntax for shell?

How can I achieve these 2 separate working tasks in just one task using the shell module?

https://stackoverflow.com/questions/65516423/ansible-if-else-using-shell-script December 31, 2020 at 11:52AM

没有评论:

发表评论