Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

How to search for a Word in a Register variable from a Shell script in Ansible?

I am very new to ansible, i am writing a set of code where the result of a shell command goes to a Register variable, and in that variable, I need to find the keyword "happy". If the keyword is found, execute ANOTHER shell script. Shell command apparently outputs multiple different values, looks like a dictionary, it is not a straight forward string, so how do i find ONE word in the entire shell result.

My attempt:

- name: execute first task
 shell: /tmp/somescript
 register: myResult
- name: another shell script
  shell: /tmp/anotherscript
  when: "happy" in myResult.

This returns saying "condition was false", when the output DOES have happy in it per the output result.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...