- name: Execute the commandin remote shell; stdout goes to the specified file on the remoteansible.builtin.shell: somescript.sh >> somelog.txt
command同shell,但是不支持管道
- 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
unarchive: 将本地的压缩包,复制到远程机器上,然后解压
- name: Extract foo.tgz into /var/lib/fooansible.builtin.unarchive:src: foo.tgzdest: /var/lib/foo
copy: 将本地的压缩包,复制到远程机器上
- name: Copy file with owner and permissionsansible.builtin.copy:src: /srv/myfiles/foo.confdest: /etc/foo.confowner: foogroup: foomode: '0644'
fetch: 将远程的包拉取到本地
- name: Store file into /tmp/fetched/host.example.com/tmp/somefileansible.builtin.fetch:src: /tmp/somefiledest: /tmp/fetched
template: 将jinjia2格式的模板,渲染到远程机器上
- name: Template a file to /etc/file.confansible.builtin.template:src: /mytemplates/foo.j2dest: /etc/file.confowner: bingroup: wheelmode: '0644'
- name: Example using fail and when togetheransible.builtin.fail:msg: The system may not be provisioned according to the CMDB status.when: cmdb_status != "to-be-staged"
wait_for: 等待端口存活
- name: Wait for port 8000 to become open on the host, don't start checking for 10 secondsansible.builtin.wait_for:port: 8000delay: 10
- name: Insert/Update "Match User" configuration block in /etc/ssh/sshd_config prepending and appending a new lineansible.builtin.blockinfile:path: /etc/ssh/sshd_configappend_newline: trueprepend_newline: trueblock: |Match User ansible-agentPasswordAuthentication no
yum: rpm包管理模块
- name: Install the latest version of Apacheansible.builtin.yum:name: httpdstate: latest
user: 创建删除用户
- name: Add the user 'johnd' with a specific uid and a primary group of 'admin'ansible.builtin.user:name: johndcomment: John Doeuid: 1040group: admin