我正在处理两个Ansible角色:一个用于引导系统,另一个用于更新操作系统和重新启动。
这些角色是由master.yml文件启动的:
---
- hosts: all
remote_user: root
roles:
- rh_bootstrap
- hosts: all
remote_user: devops
become: true
roles:
- os_update
...引导程序角色为selinux安装必要的包,添加devops用户,复制ssh密钥,并增强ssh。
---
- name: Ensure that libselinux is installed
yum:
name: libselinux-python
state: installed
- name: Create devops user
user:
name: devops
state: present
comment: Create devops user
- name: Install SSH key for devops user
authorized_key:
user: devops
key: "ssh-rsa MYKEYHERE"
state: present
- name: Make sure devops user is sudoer with no pw requirements
lineinfile:
dest: /etc/sudoers
state: present
regexp: '^devops ALL\='
line: 'devops ALL=(ALL) NOPASSWD:ALL'
validate: 'visudo -cf %s'
- name: Ensure SELinux is Enforcing
selinux:
policy: targeted
state: enforcing
- name: Disable empty password login
lineinfile: dest={{ sshd_config }} regexp="^#?PermitEmptyPasswords" line="PermitEmptyPasswords no"
notify: restart sshd
- name: Disable root SSH login
lineinfile: dest={{ sshd_config }} regexp="^#?PermitRootLogin" line="PermitRootLogin no"
notify: restart sshd
- name: Disable password login
lineinfile: dest={{ sshd_config }} regexp="^#?PasswordAuthentication" line="PasswordAuthentication no"
notify: restart sshd
...此时,master.yml切换到devops用户。devops用户在我的ansible.cfg默认值中定义了一个键。
问题是,如果我试图重新运行master.yml,根用户将无法再连接到主机,因为我已经完全禁用了根登录,因此它出错了。是否有任何优雅的方法来处理无法登录的用户?
发布于 2017-12-15 02:40:03
---
- hosts: all
remote_user: root
gather_facts: false
pre_tasks:
- block:
- wait_for_connection:
timeout: 5
rescue:
- meta: clear_host_errors
- meta: end_play
roles:
- rh_bootstrap
- hosts: all
remote_user: devops
become: true
roles:
- os_update简言之:
root被阻止);rh_bootstrap角色。西德诺特:
lineinfile,使用template。rh_bootstrap角色是一个设计缺陷。https://stackoverflow.com/questions/47824952
复制相似问题