在我的ansible剧本中,我从用户那里获取了2个输入,我还想获取第三个输入,这有时应该是可选的,如果用户提供了 var3 的值,那么剧本必须执行一个任务,否则它不应该执行,那么方法是什么为达到这个?
另外我想知道我正在使用 awx 开源 UI 进行 ansible,所以我选择主机在 ansible awx 清单中运行剧本,之后我应该在我的剧本的“主机”中写什么,或者它可以单独放置。
- name: Updating "{{ service_name }}" server codebase and starting its service.
hosts: all
tasks:
- name: Stopping nginx service
command: sudo service nginx stop
- name: Performing git checkout in the specified directory "{{ path }}"
command: git checkout .
args:
chdir: "{{ path }}"
- name: Running npm install in the directory "{{ path }}"
command: npm install
args:
chdir: "{{ path }}/node_modules"
- name: Restarting the "{{ service_name }}" service
command: sudo service "{{ service_name }}" restart
- name: Restarting the nginx service
command: sudo service nginx restart