ansible实现远程创建用户

创建yaml脚本vim user_add.yaml

复制代码
- hosts: 192.168.45.135
  remote_user: root
  tasks:
    - name: linux system add user list.
      user: name={{ item }} state=present
      with_items:
        - xiaoxin1
        - xiaoxin2
        - xiaoxin3
        - xiaoxin4

使用以下命令演练剧本ansible-playbook user_add.yaml

复制代码
ansible-playbook user_add.yaml

登录135查看已经创建成功

利用ansinble剧本模块远程机器创建文件

复制代码
- hosts: 192.168.45.135
  remote_user: root
  tasks:
    - name: linux system add user list.
      shell: touch /root/nginx-{{item}}.txt
      with_items:
        - 1.26.1

执行创建文件脚本ansible-playbook user_add1.yaml

复制代码
ansible-playbook user_add1.yaml

查看135机器上已经创建成功

定义变量,创建文件

复制代码
- hosts: 192.168.45.135
  remote_user: root
  vars:
    nginx_soft: nginx-1.26.1.tar.gz
  tasks:
    - name: linux system add user list.
      shell: touch /tmp/{{nginx_soft}}

成功执行

登录135创建成功

定义变量目录,文件名创建相应文件

复制代码
- hosts: 192.168.45.135
  remote_user: root
  vars:
    nginx_soft: nginx-1.26.1.tar.gz
    NGX_DIR: /usr/local/nginx/
  tasks:
    - name: linux system add user list.
      shell: mkdir -p {{NGX_DIR}};touch {{nginx_soft}}{{nginx_soft}};

执行演练命令

登录135查看创建成功

可以通过配置文件中的内容传递到前台页面vim index.html

编辑yaml脚本文件,vim create_wenjian.yaml,内容为将index.htm拷贝到135,136,137服务器上

复制代码
- hosts: all
  remote_user: root
  tasks:
    - name: linux system add user list.
      template: src=/root/index.html dest=/tmp/

后执行该文件

登录到135,136,138服务器即可查看到传递的内容,

相关推荐
遇见火星13 天前
如何使用Ansible一键部署MinIO集群?
ansible
粥周粥13 天前
ANSIBLE
ansible
码农101号13 天前
Linux中ansible模块补充和playbook讲解
linux·运维·ansible
码农101号13 天前
Linux的Ansible软件基础使用讲解和ssh远程连接
ansible
烟雨书信14 天前
ANSIBLE运维自动化管理端部署
运维·自动化·ansible
碎碎-li14 天前
ANSIBLE(运维自动化)
运维·自动化·ansible
@donshu@17 天前
Linux运维-ansible-python开发-获取inventroy信息
linux·运维·ansible
Kendra91920 天前
Ansible
ansible
꧁༺朝花夕逝༻꧂23 天前
Ansible小试牛刀
ansible
꧁༺朝花夕逝༻꧂23 天前
Ansible+Zabbix-agent2快速实现对多主机监控
运维·ansible