相关疑难解决方法(0)

在ansible的单个任务中使用"when"检查多个条件

我想在ansible中使用when评估多个条件,这里是我的剧本:

- name: Check that the SSH Key exists
   local_action:
     module: stat
     path: "/home/{{ login_user.stdout }}/{{ ssh_key_location }}"
   register: sshkey_result

 - name: Generating a new SSH key for the current user it's not exists already
   local_action:
      module: user
      name: "{{ login_user.stdout }}"
      generate_ssh_key: yes 
      ssh_key_bits: 2048
   when: sshkey_result.rc == 1 and  ( github_username is undefined or github_username |lower == 'none' )
Run Code Online (Sandbox Code Playgroud)

这是我的var文件供参考:

---
vpc_region: eu-west-1
key_name: my_github_key
ssh_key_location: .ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)

当我尝试执行此剧本时,我收到此错误:

TASK: [test | Check that the SSH Key exists] ********************************** …
Run Code Online (Sandbox Code Playgroud)

ansible ansible-playbook

33
推荐指数
4
解决办法
11万
查看次数

标签 统计

ansible ×1

ansible-playbook ×1