11~

11、创建一个 web content directory 创建一个名为/home/catherine/ansible/webcontent.yml 的 playbook,如下所示: ● playbook 在 dev 主机组中的受管节点上运行 ● 使用以下要求创建目录/webdev: ● 文件夹属于 webdev 组 ●常规权限:owner = read + write + execute,group = read + write + execute,other = read + execute ● 特殊权限:设置 group ID ●符号链接/var/www/html/webdev 到/webdev
● 使用一行文本创建文件/webdev/index.html,其中包含:Development [catherine@control ansible]$ cat webcontent.yml --- - name: create web content directory hosts: dev become: yes tasks: - name: start httpd service: name: httpd enabled: yes state: started - name: create directory file: path: /webdev state: directory mode: '2775' owner: root group: webdev setype:httpd_sys_content_t - name: create symbolic link file: src: /webdev dest: /var/www/html/webdev state: link setype:httpd_sys_content_t - name: create content copy:
content: 'Development' dest: /webdev/index.html setype:httpd_sys_content_t ------------------------------------------------------------------------------- 12、生成一个硬件报告(模拟环境磁盘标识符为 sda、sdb.考试时候为 vda、vdb) 创建一个名为/home/catherine/ansible/hwreport.yml 的 playbook,该 playbook 在所有被管节点上生成一个名为 /root/hwreport.txt 的输出文件,其中包含以下信息: Inventory host name 总内存(MB) BIOS 版本 磁盘设备 sda 的大小 磁盘设备 sdb 的大小 输出文件的每一行都包含一个 key = value 对。 你的 playbook 应该: 从 URL http://rhgls.sector1.example.com/materials 下载文件 hwreport.empty 并将其另存为/root/hwreport.txt 使用正确的值修改/root/hwreport.txt 如果硬件项不存在,则应将关联值设置为 NONE [catherine@control ansible]$ cat hwreport.yml --- - name: hardware report hosts: all become: yes tasks: - name: download text file to be modified get_url: url: http://rhgls.sector1.example.com/materials/hwreport.empty dest: /root/hwreport.txt - name: add host
lineinfile: path: /root/hwreport.txt regexp: '^HOST=' line: 'HOST={{ inventory_hostname }}' - name: add memory lineinfile: path: /root/hwreport.txt regexp: '^MEMORY=' line: 'MEMORY={{ ansible_memtotal_mb }}' - name: add BIOS lineinfile: path: /root/hwreport.txt regexp: '^BIOS=' line: 'BIOS={{ ansible_bios_version }}' - name: add disk vda size lineinfile: path: /root/hwreport.txt regexp: '^DISK_SIZE_VDA=' line: 'DISK_SIZE_VDA={{ ansible_devices.sda.size }}' - name: add disk vdb size lineinfile: path: /root/hwreport.txt regexp: '^DISK_SIZE_VDB=' line: 'DISK_SIZE_VDB={{ ansible_devices.sdb.size }}' when: ansible_devices.sdb is defined - name: add disk vdb size lineinfile:
path: /root/hwreport.txt regexp: '^DISK_SIZE_VDB=' line: 'DISK_SIZE_VDB=NONE' when: ansible_devices.sdb is not defined -------------------------------------------------------------------- 13、创建 Ansible 保管库以存储用户密码,如下所示: 保险库的名称是/home/catherine/ansible/locker.yml 保险库包含两个变量,如下所示: ● pw_developer 的值为 Imadev ● pw_manager 的值为 Imamgr ● 加密和解密文件库的密码是 whenyouwishuponastar //密码可以复制黏贴 ● 密码存储在文件/home/catherine/ansible/secret.txt 中 [catherine@control ansible]$ cat /home/catherine/ansible/locker.yml pw_developer: Imadev pw_manager: Imamgr [catherine@control ansible]$ cat /home/catherine/ansible/secret.txt whenyouwishuponastar [catherine@control ansible]$ cat ansible.cfg [defaults] inventory = /home/catherine/ansible/inventory roles_path = /home/catherine/ansible/roles vault_password_file = /home/catherine/ansible/secret.txt [catherine@control ansible]$ ansible-vault encrypt locker.yml Encryption successful ----------------------------------------------------------------------
14、创建用户账号 要创建的用户列表可以在名为 user_list.yml 的文件中找到,您应该从 http://rhgls.sector1.example.com/materials 下载 并将其保存到/home/catherine/ansible 使 用 在 本 次 考 试 中 其 他 地 方 创 建 的 密 码 库 /home/catherine/ansible/locker.yml , 创 建 一 个 名 为 /home/catherine/ansible/users.yml 的 playbook,用该 playbook 创建用户帐户,如下所示: 用户的 job description 为 developer: ● 在 dev 和 test 主机清单组中的主机上创建用户。 ● 设置 pw_developer 变量所对应的值为用户密码。 ● 添加到 devops 组,成为组成员。 用户的 job description 为 manager: ● 在 prod 主机清单组中的主机上创建用户。 ● 设置 pw_manager 变量所对应的值为用户密码。 ● 添加到 opsmgr 组,成为组成员。 密码应使用 SHA512 哈希格式。 您的 playbook 应该使用本考试中其他地方创建的保险库密码文件。 [catherine@control ansible]$ wget http://rhgls.sector1.example.com/materials/user_list.yml [catherine@control ansible]$ cat users.yml --- - hosts: dev test become: yes vars_files: - user_list.yml - locker.yml tasks: - name: create group devops group: name: devops state: present - name: create user
user: name: "{{ item.name }}" groups: devops append: yes password: "{{ pw_developer | password_hash('sha512') }}" loop: "{{ users }}" when: item.job == "developer" - hosts: prod become: yes vars_files: - user_list.yml - locker.yml tasks: - name: create group opsmgr group: name: opsmgr state: present - name: create user user: name: "{{ item.name }}" groups: opsmgr append: yes password: "{{ pw_developer | password_hash('sha512') }}" loop: "{{ users }}" when: item.job == "manager" ------------------------------------------------------------------------ 15、更新 Ansible 保管库密钥 更新 Ansible 保管库密钥,如下所示: ● 从 http://rhgls.sector1.example.com/materials/salaries.yml 下 载 Ansible 保 管 库 并 将 其 保 存 为
/home/catherine/ansible/salaries.yml ● 当前的保管库密码是 insecure4sure //密码可以复制黏贴 ● 新的保管库密码是 bbe2de98389b ● 保管库使用新密码保持加密状态 [catherine@control ansible]$ wget http://rhgls.sector1.example.com/materials/salaries.yml
[catherine@control ansible]$ ansible-vault rekey salaries.yml --ask-vault-pass Vault password: insecure4sure New Vault password: bbe2de98389b Confirm New Vault password: bbe2de98389b

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐