3.8.1
--- - name: 3.8.1zuoye hosts: all gather_facts: true tasks: - name: 输出DNS服务器IP debug: msg: "当前受管主机的DNS服务器IP:{{ansible_dns.nameservers}}"
3.8.2
--- - name: 3.8.2zuoye hosts: all become: yes tasks: - yum: name: httpd state: present - name: copy example.conf copy: src: example.conf dest: /etc/httpd/conf.d/example.conf notify: restart_httpd - name: copy index.html copy: dest: /var/www/html/index.html content: zuoye handlers: - name: restart_httpd service: name: httpd state: restarted
第四章作业
![]()
4.
--- - name: 3.8.3zuoye hosts: all become: yes gather_facts: true tasks: - name: copy /home/file copy: dest: /home/file content: | hostname= {{ inventory_hostname }} memory= {{ ansible_memtotal_mb }} BIOS version= {{ ansible_bios_version }} distribution= {{ ansible_distribution }} {{ ansible_distribution_version }} size of disk device is {{ ansible_devices["dm-0"].size }}
第五章作业
![]()
5.6.1
--- - name: 根分区大于1G时安装并启动服务 hosts: all gather_facts: yes become: yes tasks: - name: 安装httpd和mariadb-server(根分区大于1G时) ansible.builtin.yum: name: - httpd - mariadb-server state: present when: ansible_mounts | selectattr('mount', 'equalto', '/') | map(attribute='size_total') | first > 1073741824 - name: 确保httpd服务已启动并开机自启 ansible.builtin.service: name: httpd state: started enabled: yes when: ansible_mounts | selectattr('mount', 'equalto', '/') | map(attribute='size_total') | first > 1073741824 - name: 确保mariadb服务已启动并开机自启 ansible.builtin.service: name: mariadb state: started enabled: yes when: ansible_mounts | selectattr('mount', 'equalto', '/') | map(attribute='size_total') | first > 1073741824
5.6.2
--- - name: 5.6.2zuoye hosts: all become: true tasks: - name: copy Development copy: dest: /etc/message content: "Development\n" when: inventory_hostname in groups.get('dev', []) - name: copy test copy: dest: /etc/message content: "Test\n" when: inventory_hostname in groups.get('test', [])