--- - hosts: '{{ host }}' user: root tasks: - name: 修改root密码 register: rootpw_result shell: | root_pw=$(date +"%s%N"| sha256sum | base64 | head -c 24) echo "$root_pw" | passwd --stdin root 2>&1 >/dev/null echo "{{ ansible_ssh_host }} : $root_pw" #- debug: var=rootpw_result.stdout_lines #- debug: msg={{ rootpw_result.stdout_lines }} #密码存到本地文件中 #- local_action: copy content="{{ rootpw_result.stdout_lines }}\n" dest=~/GIT/serverlist/{{ root_passwd }} - local_action: lineinfile state=present line={{ rootpw_result.stdout_lines }} dest=~/GIT/serverlist/{{ root_passwd }}
使用方法
ansible-playbook -i ~/GIT/serverlist/server_list_17225.txt change_root_passwd.yml -e "host=rackspace_172_25_test root_passwd=20220523_password.txt"
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏