和文件处理相关的模块
1. 文件在管理结点上:copy: 改内容
- name: For dev
copy:
content: "Development"
dest: /etc/issue
when: ansible_hostname in groups['dev']
file: 创建目录和链接:
- name: Create directory /webdev
file:
path: /webdev
state: directory
recurse: yes
group: webdev
mode: '2775'
setype: httpd_sys_content_t
- name: Create link file
file:
src: /webdev
dest: /var/www/html/webdev
template: 活的内容的file
- name: Create hosts for dev
template:
src: hosts.j2
dest: /etc/myhosts
when: ansible_hostname in groups['dev']2. 文件在受管结点上:
geturl:
- name: Get hwreport file to /root/hwreport.txt
get_url:
url: http://classroom.example.com/content/hwreport.empty
dest: /root/hwreport.txt
3. 处理内容最强的模块:
- name: Ensure SELinux is set to enforcing mode
lineinfile:
path: /etc/selinux/config
regexp: '^SELINUX='
line: SELINUX=enforcing
- name: Make sure group wheel is not in the sudoers configuration
lineinfile:
path: /etc/sudoers
state: absent
regexp: '^%wheel'
- name: Replace a localhost entry with our own
lineinfile:
path: /etc/hosts
regexp: '^127\.0\.0\.1'
line: 127.0.0.1 localhost
owner: root
group: root
mode: '0644'
- name: Ensure the default Apache port is 8080
lineinfile:
path: /etc/httpd/conf/httpd.conf
regexp: '^Listen '
insertafter: '^#Listen '
line: Listen 8080
- name: Ensure we have our own comment added to /etc/services
lineinfile:
path: /etc/services
regexp: '^# port for http'
insertbefore: '^www.*80/tcp'
line: '# port for http by default'
- name: Insert/Update eth0 configuration stanza in /etc/network/interfaces
(it might be better to copy files into /etc/network/interfaces.d/)
blockinfile:
path: /etc/network/interfaces
block: |
iface eth0 inet static
address 192.0.2.23
netmask 255.255.255.0
--------进行测试:
---
- name: Test file
hosts: servera
tasks:
- name: File
file:
path: /tmp/block.txt
state: touch
- name: Block
blockinfile:
path: /tmp/block.txt
block: |
iface eth0 inet static
address 192.0.2.23
netmask 255.255.255.0
页:
[1]