我试图读取文件的内容,将它们存储在变量中,然后将它们插入到另一个文件中(如果它们尚不存在).
所以,我试图解决这个问题的方法如下:
# Create a variable that represents the path to the file that you want to read from
ssh_public_key_file: '../../jenkins_master/files/{{ hostvars[inventory_hostname]["environment"] }}/id_rsa.pub'
# Create a variable that represents the contents of this file:
ssh_public_key: "{{ lookup('file', '{{ ssh_public_key_file }}') }}"
Run Code Online (Sandbox Code Playgroud)
然后我在Ansible playbook中使用这些变量,如下所示:
- name: Install SSH authorized key
lineinfile: create=yes dest=~/.ssh/authorized_keys line=" {{ ssh_public_key }}" mode=0644
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行该剧本时,我收到以下错误消息:
could not locate file in lookup: {{ ssh_public_key_file }}
Run Code Online (Sandbox Code Playgroud)
任何人都可以推荐一个解决方案或建议我可能做错了什么?
谢谢,
SEAN
有谁知道如何只提取存储库的pylint分数?
因此,假设pylint产生以下输出:
Global evaluation
-----------------
Your code has been rated at 6.67/10 (previous run: 6.67/10, +0.00)
Run Code Online (Sandbox Code Playgroud)
我希望它返回值6.67.
谢谢,
SEAN