The use of Ansible also has a long time, the previous machine is a good template, configuration of SSH without password landing, push up generally very convenient. Today, there is nothing to do, just have a thing to do, the plaintext password push sample paste out to share.
Straight into the topic,
Requirements: Modify the Hosts file of a batch of machines, require sudo permission, and sudo account (I am here is CentOS account,) No SSH password login is not configured. (The CentOS account has been added with sudo privileges in/etc/sudoers)
Here I want to lazy, do not want a set to configure the key SSH login, simply use ansible plaintext password push to complete this function.
Note: About Ansilbe installation, yml file use, SSH keyless entry, the Hosts file configuration is not covered in this article. Getting started posts should be huge on-line.
The first step: Configure the/etc/ansible/hosts file, set up the management group;
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/85/9A/wKiom1epm8fQ5gITAALR-tzPQFg780.jpg "title=" 11111. JPG "alt=" wkiom1epm8fq5gitaalr-tzpqfg780.jpg "/>
Step Two: Configure the Yml file to perform the required actions in bulk
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/9A/wKiom1epnDSCh0uKAADbWmf58Og399.jpg "title=" 222222.jpg "alt=" Wkiom1epndsch0ukaadbwmf58og399.jpg "/>
Step three: Ansible-playbook batch execution:
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/85/99/wKioL1epnF7wR_8ZAADSOj5uXow811.jpg "style=" float: none; "title=" success1.jpg "alt=" Wkiol1epnf7wr_8zaadsoj5uxow811.jpg "/>
650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M01/85/99/wKioL1epnF-QjNMJAAFzOgQ03v8188.jpg "style=" float: none; "title=" success3.jpg "alt=" Wkiol1epnf-qjnmjaafzogq03v8188.jpg "/>
Key points for additional information:
Official Document: Http://docs.ansible.com/ansible/become.html
With regard to the use of become, when it is necessary to perform some special operations require specialized permissions, you can use become_user that emphasis switch, while the 1.9 version of the previous sudo_user also remain in use;
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/99/wKioL1epnh6T5JaGAADo42_zoKU111.jpg "title=" Become.jpg "alt=" Wkiol1epnh6t5jagaado42_zoku111.jpg "/>
2. When using Beocome_user, and specifying that sudo is required, you need to specify the Ansible_sudo_pass password in the Hosts file, otherwise Become_user does not execute without permission when using sudo, and will not succeed. For example, I use the CentOS account to perform echo "127.0.0.1 $ (hostname)" >>/etc/hosts requires sudo permission, so with Become_user:root, and specified ansible_sudo_ Pass the password so that it can be executed smoothly.
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/85/9A/wKiom1epnj_Rq3e4AADrQ-ucqPk084.jpg "style=" float: none; "title=" 222.jpg "alt=" Wkiom1epnj_rq3e4aadrq-ucqpk084.jpg "/>
650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/85/99/wKioL1epnj_xTUlnAADi0u7-83k936.jpg "style=" float: none; "title=" 111111hosts.jpg "alt=" Wkiol1epnj_xtulnaadi0u7-83k936.jpg "/>
Finally, paste the Yml file for your reference:
---
-Hosts:office-zhaoman-spider
Sudo_user:centos
Sudo:yes
Tasks
-Name:echo/etc/hosts
Shell:echo "127.0.0.1 $ (hostname)" >>/etc/hosts
Ignore_errors:true
Become:true
Become_user:root
-Name:cat/etc/hosts
Shell:cat/etc/hosts
Ignore_errors:false
-Shell:cat/etc/hosts
Register:ps
-Debug:var=ps.stdout_lines
This article is from "Good Sir 2020" blog, please make sure to keep this source http://fuyuan2016.blog.51cto.com/8678344/1836199
Ansible Bulk Push Ansible_ssh_pass + ansible_sudo_pass+ become use case