Ansible 1.9.1'成为'和sudo问题

ili*_*007 14 bash sudo ansible ansible-playbook

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

在我的ansible.cfg文件中使用'new'Ansible Privilege Escalation配置选项时:

[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
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

fatal: [webserver1.local] => Internal Error: this module does not support running commands via 'sudo'

FATAL: all hosts have already failed -- aborting
Run Code Online (Sandbox Code Playgroud)

剧本也很简单:

# 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
Run Code Online (Sandbox Code Playgroud)

我不确定Ansible 1.9.1中是否有什么东西坏了,或者我做错了什么.当然,Ansible中的'command'模块允许将命令作为sudo运行.

Max*_*xym 30

问题在于配置; 我也把作为一个例子,并得到了同样的问题.玩了一段时间后,我注意到以下工作:

1)弃用sudo:

---
- hosts: all
  sudo: yes
  gather_facts: no
  tasks:
  - name: "sudo to root"
    command: /usr/bin/whoami
Run Code Online (Sandbox Code Playgroud)

2)新的 become

---
- hosts: all
  become: yes
  become_method: sudo
  gather_facts: no
  tasks:
  - name: "sudo to root"
    command: /usr/bin/whoami
Run Code Online (Sandbox Code Playgroud)

3)使用ansible.cfg:

[privilege_escalation]
become = yes
become_method = sudo
Run Code Online (Sandbox Code Playgroud)

然后在剧本中:

---
- hosts: all
  gather_facts: no
  tasks:
  - name: "sudo to root"
    command: /usr/bin/whoami
Run Code Online (Sandbox Code Playgroud)

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

  become_user = tstuser01
Run Code Online (Sandbox Code Playgroud)

至少这是我在ansible.cfg中定义remote_user的方式,它的工作方式......我的问题已解决,希望你的问题也解决了

  • 问题肯定是ansible.cfg中的become_user和become_method选项的引号.rpm示例错误地包含引号; 删除引号会导致它工作. (2认同)

小智 0

我认为您应该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
Run Code Online (Sandbox Code Playgroud)