12、生成硬件报告创建一个名为 /home/student/ansible/hwreport.yml的 playbook,它将在所有受管节点上生成含有以下信息的输出文件 /root/hwreport.txt:
输出文件中的每一行含有一个 key=value 对 。
您的 playbook 应当:从 http://content.example.com/hwreport.empty 下载文件,并将它保存为/root/hwreport.txt使用正确的值修改 /root/hwreport.txt如果硬件项不存在,相关的值应设为NONE
解答:[student@workstation ansible]$ vim hwreport.yml---- name: get hwreporthosts: alltasks:- name: Create report fileget_url:url: http://content.example.com/hwreport.emptydest: /root/hwreport.txt- name: get inventory_hostnamereplace:path: /root/hwreport.txtregexp: 'inventoryhostname'replace: "{{ inventory_hostname }}"- name: get memreplace:path: /root/hwreport.txtregexp: 'memory_in_MB'replace: "{{ ansible_memtotal_mb }}"- name: get biosreplace:path: /root/hwreport.txtregexp: 'BIOS_version'replace: "{{ ansible_bios_version }}"- name: get vdareplace:path: /root/hwreport.txtregexp: 'disk_vda_size'replace: "{{ ansible_devices.vda.size if ansible_devices.vda is defined else 'NONE'}}"- name: get vdbreplace:path: /root/hwreport.txtregexp: 'disk_vdb_size'replace: "{{ ansible_devices.vdb.size if ansible_devices.vdb is defined else 'NONE'}}"[student@workstation ansible]$ ansible-playbook hwreport.yml
13、创建密码库按照下方所述,创建一个 Ansible 库来存储用户密码:库名称为 /home/student/ansible/locker.yml库中含有两个变量,名称如下:pw_developer,值为 Imadevpw_manager,值为 Imamgr用于加密和解密该库的密码为whenyouwishuponastar密码存储在文件 /home/student/ansible/secret.txt中
解答:[student@workstation ansible]$ vim locker.yml---pw_developer: lmadevpw_manager: lmamgr[student@workstation ansible]$ echo whenyouwishuponastar > secret.txt[student@workstation ansible]$ chmod 600 secret.txt[student@workstation ansible]$ ansible-vault encrypt locker.yml --vault-id=/home/student/ansible/secret.txt
14、创建用户账户从 http://content.example.com/user_list.yml 下载要创建的用户的列表,并将它保存到 /home/student/ansible在本次考试中使用在其他位置创建的密码库 /home/student/ansible/locker.yml,创建名为/home/student/ansible/users.yml 的playbook,从而按以下所述创建用户帐户:职位描述为 developer 的用户应当:在 dev 和 test 主机组中的受管节点上创建从 pw_developer 变量分配密码,密码有效期为30天是附加组 student 的成员职位描述为 manager 的用户应当:在 prod 主机组中的受管节点上创建从 pw_manager 变量分配密码,密码有效期为30天是附加组 opsmgr 的成员密码应采用 SHA512 哈希格式 。您的 playbook 应能够在本次考试中使用在其他位置创建的库密码文件/home/student/ansible/secret.txt 正常运行
解答:[student@workstation ansible]$ wget http://content.example.com/user_list.yml[student@workstation ansible]$ vim users.yml---- name: create developer userhosts: dev, testvars_files:- /home/student/ansible/locker.yml- /home/student/ansible/user_list.ymltasks:- name: create group studentgroup:name: studentstate: present- name: create user in developeruser:name: "{{ item.name }}"groups: studentpassword: "{{ pw_developer | password_hash('sha512') }}"state: presentloop: "{{ users }}"when: item.job == "developer"- name: chageshell:cmd: chage -M 30 {{ item.name }}loop: "{{ users }}"when: item.job == "developer"- name: create manager userhosts: prodvars_files:- /home/student/ansible/locker.yml- /home/student/ansible/user_list.ymltasks:- name: create group opsmgrgroup:name: opsmgrstate: present- name: create user in manageruser:name: "{{ item.name }}"groups: opsmgrpassword: "{{ pw_manager | password_hash('sha512') }}"state: presentloop: "{{ users }}"when: item.job == "manager"- name: chage1shell:cmd: chage -M 30 {{ item.name }}loop: "{{ users }}"when: item.job == "manager"[student@workstation ansible]$ ansible-playbook users.yml --vault-id secret.txt