Ansible 1.9.1 'become'和 sudo 问题



我正在尝试运行一个非常简单的剧本来测试新的 Ansible 设置。

在我的 ansible.cfg 文件中使用"新"Ansible 权限提升配置选项时:

[defaults]
host_key_checking=false
log_path=./logs/ansible.log
executable=/bin/bash
#callback_plugins=./lib/callback_plugins
######
[privilege_escalation]
become=True
become_method='sudo'
become_user='tstuser01'
become_ask_pass=False
[ssh_connection]
scp_if_ssh=True

我收到以下错误:

fatal: [webserver1.local] => Internal Error: this module does not support running commands via 'sudo'
FATAL: all hosts have already failed -- aborting

剧本也很简单:

# Checks the hosts provisioned by midrange
---
- name: Test su connecting as current user
  hosts: all
  gather_facts: no
  tasks:
  - name: "sudo to configued user -- tstuser01"
    #action: ping
    command: /usr/bin/whoami

我不确定 Ansible 1.9.1 中是否有问题,或者我是否做错了什么。当然,Ansible 中的"命令"模块允许以 sudo 的形式运行命令。

问题出在配置上;我也以它为例,遇到了同样的问题。玩了一会儿后,我注意到以下内容有效:

1) 已弃用sudo

---
- hosts: all
  sudo: yes
  gather_facts: no
  tasks:
  - name: "sudo to root"
    command: /usr/bin/whoami

2) 新become

---
- hosts: all
  become: yes
  become_method: sudo
  gather_facts: no
  tasks:
  - name: "sudo to root"
    command: /usr/bin/whoami

3)使用Ansible.cfg:

[privilege_escalation]
become = yes
become_method = sudo

然后在剧本中:

---
- hosts: all
  gather_facts: no
  tasks:
  - name: "sudo to root"
    command: /usr/bin/whoami

既然你"成为"tstuser01(不是像我这样的根),请玩一下,可能用户名也不应该被引用:

  become_user = tstuser01

至少这是我在 Ansible 中定义remote_user的方式.cfg而且它有效......我的问题解决了,希望你也<</p>

div class="one_answers">我认为

您应该在 hosts 部分中使用 sudo 指令,以便后续任务可以使用 sudo 权限运行,除非您在任务中明确指定sudo:no

这是我修改为使用sudo指令的剧本。


# Checks the hosts provisioned by midrange
---
- hosts: all
  sudo: yes
  gather_facts: no
  tasks:
    - name: "sudo to configued user -- tstuser01"
      command: /usr/bin/whoami

相关内容

  • 没有找到相关文章

最新更新