Ansible 如何在查找时进行权限提升(ini)
MyAnsible 如何在查找时进行权限提升(ini),ansible,ini,Ansible,Ini,Mytest.yml 1 - name: Test ini 2 hosts: localhost 3 connection: local 4 become: true 5 6 tasks: 7 8 - name: Verifying /etc/heat/heat.conf Configuration 9 become_user: root 10
test.yml
1 - name: Test ini
2 hosts: localhost
3 connection: local
4 become: true
5
6 tasks:
7
8 - name: Verifying /etc/heat/heat.conf Configuration
9 become_user: root
10 become_method: sudo
11 fail: msg="Unable to set in /etc/heat/heat.conf"
12 when: "lookup('ini', 'max_resources_per_stack section=DEFAULT file=/etc/heat/heat.conf') != '-1'"
错误
更新
只有当我使用sudo
像sudo ansible playbook ini\u test.yml那样运行playbook时,playbook才起作用
1 - name: Test ini
2 hosts: localhost
3 connection: local
4 become: true
5
6 tasks:
7
8 - name: Verifying /etc/heat/heat.conf Configuration
9 become_user: root
10 become_method: sudo
11 fail: msg="Unable to set in /etc/heat/heat.conf"
12 when: "lookup('ini', 'max_resources_per_stack section=DEFAULT file=/etc/heat/heat.conf') != '-1'"
更新2
ansible 2.6.11
这是一个很好的例子
使用文件/root/test
> ll /root/test
-rw-r----- 1 root root 30 May 29 15:09 /root/test
剧本
- hosts: localhost
become_user: root
become_method: sudo
become: yes
tasks:
- command: whoami
register: result
- debug:
var: result.stdout
- name: read the file
debug:
msg: "{{ lookup('file', '/root/test') }}"
给出(节略):
剧本按预期运行,并给出(节略):
记录在案 是的
使用文件/root/test
> ll /root/test
-rw-r----- 1 root root 30 May 29 15:09 /root/test
剧本
- hosts: localhost
become_user: root
become_method: sudo
become: yes
tasks:
- command: whoami
register: result
- debug:
var: result.stdout
- name: read the file
debug:
msg: "{{ lookup('file', '/root/test') }}"
给出(节略):
剧本按预期运行,并给出(节略):
记录在案 @VladimirBotka感谢您的评论。我已经更新了问题,请检查我是否能够重现问题。作为root用户,我无法使用权限-rw-r-----
查找由root:root
拥有的文件。错误是原始消息:在查找中找不到文件。权限-rw-r--r--
工作正常。这是一个好消息。@VladimirBotka谢谢你的评论。我已经更新了问题,请检查我是否能够重现问题。作为root用户,我无法使用权限-rw-r-----
查找由root:root
拥有的文件。错误是原始消息:在查找中找不到文件。权限-rw-r--r--
工作正常。这是一个错误,我还是有同样的错误。但是我在剧本的开头已经提到了been:true
。更新了ansible版本的问题,以便为我挖掘。所以,我想我使用了crudini--get
:-(我仍然会遇到同样的错误。但我已经在playbook的开头提到了been:true
。用ansible VersionTanks更新了问题供我挖掘。所以,我想我使用了crudini--get
:-(
> ll /root/test
-rw-r--r-- 1 root root 30 May 29 15:09 /root/test
TASK [read the file]
ok: [localhost] => {
"msg": "Wed May 29 15:09:43 CEST 2019"
}