ansible常用的模块

  1. shell: 执行相关命令,支持管道:
shell 复制代码
- name: Execute the command in remote shell; stdout goes to the specified file on the remote
  ansible.builtin.shell: somescript.sh >> somelog.txt
  1. command同shell,但是不支持管道
powershell 复制代码
- name: Run command if /path/to/database does not exist (without 'args')
  ansible.builtin.command: /usr/bin/make_database.sh db_user db_name creates=/path/to/database
  1. unarchive: 将本地的压缩包,复制到远程机器上,然后解压
shell 复制代码
- name: Extract foo.tgz into /var/lib/foo
  ansible.builtin.unarchive:
    src: foo.tgz
    dest: /var/lib/foo
  1. copy: 将本地的压缩包,复制到远程机器上
powershell 复制代码
- name: Copy file with owner and permissions
  ansible.builtin.copy:
    src: /srv/myfiles/foo.conf
    dest: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'
  1. fetch: 将远程的包拉取到本地
shell 复制代码
- name: Store file into /tmp/fetched/host.example.com/tmp/somefile
  ansible.builtin.fetch:
    src: /tmp/somefile
    dest: /tmp/fetched
  1. template: 将jinjia2格式的模板,渲染到远程机器上
shell 复制代码
- name: Template a file to /etc/file.conf
  ansible.builtin.template:
    src: /mytemplates/foo.j2
    dest: /etc/file.conf
    owner: bin
    group: wheel
    mode: '0644'
  1. file: 创建和删除文件或目录
powershell 复制代码
- name: Change file ownership, group and permissions
  ansible.builtin.file:
    path: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'
  1. fail:失败模块,遇到立即停止运行ansible
powershell 复制代码
- name: Example using fail and when together
  ansible.builtin.fail:
    msg: The system may not be provisioned according to the CMDB status.
  when: cmdb_status != "to-be-staged"
  1. wait_for: 等待端口存活
powershell 复制代码
- name: Wait for port 8000 to become open on the host, don't start checking for 10 seconds
  ansible.builtin.wait_for:
    port: 8000
    delay: 10
  1. selinux: 启动或者关闭selinux
shell 复制代码
- name: Enable SELinux
  selinux:
    policy: targeted
    state: enforcing
  1. blockinfile:渲染指定内容到某个文件内
shell 复制代码
- name: Insert/Update "Match User" configuration block in /etc/ssh/sshd_config prepending and appending a new line
  ansible.builtin.blockinfile:
    path: /etc/ssh/sshd_config
    append_newline: true
    prepend_newline: true
    block: |
      Match User ansible-agent
      PasswordAuthentication no
  1. yum: rpm包管理模块
shell 复制代码
- name: Install the latest version of Apache
  ansible.builtin.yum:
    name: httpd
    state: latest
  1. user: 创建删除用户
shell 复制代码
- name: Add the user 'johnd' with a specific uid and a primary group of 'admin'
  ansible.builtin.user:
    name: johnd
    comment: John Doe
    uid: 1040
    group: admin
相关推荐
wdfk_prog1 小时前
ROS教程:01 搭建 ROS1 Noetic Docker 开发环境
运维·缓存·docker·容器·ros
SEO_juper1 小时前
Java 并发编程实战:从线程基础到高并发架构
运维·人工智能·爬虫·chatgpt·seo
szephyr2 小时前
Docker + Compose 实战:把本地项目一键搬到云服务器,附完整配置
运维·docker·容器·部署·云服务器
wdfk_prog2 小时前
ros教程02:创建 catkin Workspace、Package 与第一个 ROS1 C++ Node
运维·缓存·docker·容器·ros
亚川楼宇自控系统数据中心厂家2 小时前
高校 / 医院 / 政务云数据中心 IBMS 系统怎么落地?
运维
陈陈CHENCHEN3 小时前
【Linux】服务器根目录磁盘扩容操作记录
linux·运维·服务器
见闻小天地5 小时前
从晶片工艺到可靠性验证:晶威特TF-3215型RTC晶振全面解析
运维·业界资讯
名字还没想好☜6 小时前
Docker 网络实战:bridge/host/none/自定义网络、容器互通与端口映射踩坑
运维·docker·kubernetes
fengyehongWorld6 小时前
Linux squid搭建基础代理服务器
linux·运维·服务器
木白CPP6 小时前
Linux DMA驱动详解(二)-----DMA的使用者
java·linux·运维