今天发现要在shell命令中使用大括号{{}}
刚开始的playbook如下:
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/usr/bin/ansible-playbook ############################# - hosts: localhost remote_user: root gather_facts: false tasks: - name: "{{ check_command }}" shell: /usr/bin/oc get secrets -n namespace secrentname --template '{{ index .data "abc.crt" }}' | base64 -d | openssl x509 -noout -text|grep After register: ssl_out - debug: var=ssl_out |
发现有两个问题,单引号需要转义,大括号需要转义
ansible 的shell模块中对于单引号的转义很简单”,两个连续的单引号就可以了
但是对于大括号则需要:{{ ‘{{‘ }} {{ ‘}}’ }} 转义后变成 {{}}
所以上边的playbook变成:
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/usr/bin/ansible-playbook ############################ - hosts: localhost remote_user: root gather_facts: false tasks: - name: get secret shell: "/usr/bin/oc get secrets -n namespace secretname --template '{{ '{{' }} index .data \"abc.crt\" {{ '}}' }}' | base64 -d | openssl x509 -noout -text|grep After" register: result - debug: var=result.stdout |
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021
不爱留名的黄首席 2019/03/07 21:34
楼主你试一下 `oc get secret registry-certificates -o jsonpath='{.data.registry\.crt}' | base64 -d | openssl x509 -noout -enddate`,更优雅