Bo's Oracle Station

查看: 2255|回复: 0

和文件处理相关的模块

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2020-12-5 21:31:21 | 显示全部楼层 |阅读模式
1. 文件在管理结点上:
copy: 改内容
  1. - name: For dev
  2. copy:
  3. content: "Development"
  4. dest: /etc/issue
  5. when: ansible_hostname in groups['dev']
复制代码

file: 创建目录和链接:
  1. - name: Create directory /webdev
  2. file:
  3. path: /webdev
  4. state: directory
  5. recurse: yes
  6. group: webdev
  7. mode: '2775'
  8. setype: httpd_sys_content_t
复制代码

  1. - name: Create link file
  2. file:
  3. src: /webdev
  4. dest: /var/www/html/webdev
复制代码


template: 活的内容的file

  1. - name: Create hosts for dev
  2. template:
  3. src: hosts.j2
  4. dest: /etc/myhosts
  5. when: ansible_hostname in groups['dev']
复制代码
2. 文件在受管结点上:
geturl:
  1. - name: Get hwreport file to /root/hwreport.txt
  2. get_url:
  3. url: http://classroom.example.com/content/hwreport.empty
  4. dest: /root/hwreport.txt
复制代码

3. 处理内容最强的模块:
  1. - name: Ensure SELinux is set to enforcing mode
  2.   lineinfile:
  3.     path: /etc/selinux/config
  4.     regexp: '^SELINUX='
  5.     line: SELINUX=enforcing

  6. - name: Make sure group wheel is not in the sudoers configuration
  7.   lineinfile:
  8.     path: /etc/sudoers
  9.     state: absent
  10.     regexp: '^%wheel'

  11. - name: Replace a localhost entry with our own
  12.   lineinfile:
  13.     path: /etc/hosts
  14.     regexp: '^127\.0\.0\.1'
  15.     line: 127.0.0.1 localhost
  16.     owner: root
  17.     group: root
  18.     mode: '0644'

  19. - name: Ensure the default Apache port is 8080
  20.   lineinfile:
  21.     path: /etc/httpd/conf/httpd.conf
  22.     regexp: '^Listen '
  23.     insertafter: '^#Listen '
  24.     line: Listen 8080

  25. - name: Ensure we have our own comment added to /etc/services
  26.   lineinfile:
  27.     path: /etc/services
  28.     regexp: '^# port for http'
  29.     insertbefore: '^www.*80/tcp'
  30.     line: '# port for http by default'
复制代码
  1. - name: Insert/Update eth0 configuration stanza in /etc/network/interfaces
  2.         (it might be better to copy files into /etc/network/interfaces.d/)
  3.   blockinfile:
  4.     path: /etc/network/interfaces
  5.     block: |
  6.       iface eth0 inet static
  7.           address 192.0.2.23
  8.           netmask 255.255.255.0
复制代码


--------进行测试:
  1. ---
  2. - name: Test file
  3.   hosts: servera
  4.   tasks:
  5.   - name: File
  6.     file:
  7.       path: /tmp/block.txt
  8.       state: touch

  9.   - name: Block
  10.     blockinfile:
  11.       path: /tmp/block.txt
  12.       block: |
  13.         iface eth0 inet static
  14.             address 192.0.2.23
  15.             netmask 255.255.255.0
复制代码




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-11-1 08:36 , Processed in 0.042550 second(s), 24 queries .

快速回复 返回顶部 返回列表