vim ss-s.yml
- hosts: webserver
remote_user: admin1
tasks:
- name: "ss -s"
shell: source /etc/profile;ss -s
register: shell_result
- debug:
var: shell_result.stdout_lines
ansible-playbook ss-s.yml
hosts组为webserver 在/etc/ansible/hosts中配置的主机
remote_user为执行命令的用户