【发布时间】:2020-07-07 12:30:01
【问题描述】:
我是 ansible 的新手。
我正在尝试创建一个角色,我以 root 身份启动 playbook,然后在下一场比赛中我切换到另一个用户并继续。以下文件位于角色本身内。
---
# tasks file for /etc/ansible/roles/dashmn
#
- name: create users logged in as root
remote_user: root
import_tasks: whoami.yml
import_tasks: create_users.yml
import_tasks: set_sudoer.yml
- name: log in as dashadmin
remote_user: dashadmin
become: true
import_tasks: whoami.yml
import_tasks: disable_rootlogin.yml
import_tasks: update_install_reqs.yml
import_tasks: configure_firewall.yml
import_tasks: add_swap.yml
我添加了一个将用户添加到 /etc/sudoer.d 的 sudoer 任务
---
- name: set passwordless sudo
lineinfile:
path: /etc/sudoers
state: present
regexp: '^%sudo'
line: '%sudo ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'
我创建了一个使用我创建的角色的 deploy.yml,如下所示。
---
- hosts: test-mn
roles:
- dashmn
当我对 deploy.yml 进行语法检查时
[DEPRECATION WARNING]: The TRANSFORM_INVALID_GROUP_CHARS settings is set to allow bad characters in group names
by default, this will change, but still be user configurable on deprecation. This feature will be removed in
version 2.10. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details
[WARNING]: While constructing a mapping from /etc/ansible/roles/dashmn/tasks/main.yml, line 4, column 3, found
a duplicate dict key (import_tasks). Using last defined value only.
[WARNING]: While constructing a mapping from /etc/ansible/roles/dashmn/tasks/main.yml, line 10, column 3, found
a duplicate dict key (import_tasks). Using last defined value only.
任何关于如何组织它以使其更好的帮助将不胜感激。
现在,我的问题是,如果在任务文件中我自己删除了剧本,只保留 import_tasks 一切正常,但它不使用用户 dashadmin,它使用 root。
我想创建用户,然后只以 dashadmin 身份登录并以 dashadmin 身份工作。
我也遇到了错误
FAILED! => {"msg": "Missing sudo password"}
显然有什么地方出错了,只是不确定我哪里出错了。
这里是 /etc/sudoers 文件
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL) NOPASSWD: ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
【问题讨论】:
标签: ansible ansible-2.x