Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

linux - Formatting the symmetric_difference output

I'm fetching the difference of certain command outputs pre and post reboot and trying to compare using the ansible filters {precheck | symmetric_difference(postcheck) } but the comparison output comes in single line for each item. Is there any filters I can add to make it line by line output or proper formatting:

Current Output: redhat-release [u'Red Hat Enterprise Linux Server release 7.8 (Maipo)', u'Red Hat Enterprise Linux Server release 7.9 (Maipo)']

sysctl_all

[u'fs.dentry-state = 362582217245091430', u'fs.epoll.max_user_watches = 380600', u'fs.file-max = 183609', u'fs.file-nr = 12160183609', u'fs.inode-nr = 27231334', u'fs.inode-state = 2723133400000', u'kernel.kptr_restrict = 0', u'kernel.ns_last_pid = 18725', u'kernel.osrelease = 3.10.0-1127.el7.x86_64', u'kernel.random.boot_id = 4c861129-7362-4bd6-8dea-632234a7bfb4', u'kernel.random.entropy_avail = 801', u'kernel.random.uuid = 377c4ea9-059a-4646-9d2e-b808a6b00fd7', u'kernel.threads-max = 14518', u'kernel.version = #1 SMP Tue Feb 18 16:39:12 EST 2020', u'net.ipv4.udp_mem = 435575807687114', u'net.netfilter.nf_conntrack_count = 1', u'user.max_ipc_namespaces = 7259', u'user.max_mnt_namespaces = 7259', u'user.max_net_namespaces = 7259', u'user.max_pid_namespaces = 7259', u'user.max_uts_namespaces = 7259', u'vm.user_reserve_kbytes = 56422', u'fs.dentry-state = 286701432045048690', u'fs.epoll.max_user_watches = 380661', u'fs.file-max = 176875', u'fs.file-nr = 12800176875', u'fs.inode-nr = 24008322', u'fs.inode-state = 2400832200000', u'kernel.kptr_restrict = 1', u'kernel.ns_last_pid = 5597', u'kernel.osrelease = 3.10.0-1160.6.1.el7.x86_64', u'kernel.random.boot_id = 3902ab24-35fe-469f-8607-755bddfb75f3', u'kernel.random.entropy_avail = 1104', u'kernel.random.uuid = 06afecb2-e35e-4053-a5c9-ba703e89d4fc', u'kernel.threads-max = 14520', u'kernel.version = #1 SMP Wed Oct 21 13:44:38 EDT 2020', u'net.ipv4.udp_mem = 435635808487126', u'net.netfilter.nf_conntrack_count = 17', u'user.max_ipc_namespaces = 7260', u'user.max_mnt_namespaces = 7260', u'user.max_net_namespaces = 7260', u'user.max_pid_namespaces = 7260', u'user.max_uts_namespaces = 7260', u'vm.user_reserve_kbytes = 55022']

systemctl_units

[u'25 loaded units listed. Pass --all to see loaded but inactive units, too.', u'systemd-hostnamed.service loaded active running Hostname Service', u'26 loaded units listed. Pass --all to see loaded but inactive units, too.']

Below is the yaml file snip I'm using to extract the output:

    - name: Precheck - Postcheck Comparison
      vars:
        prech: "{{ query('lines','cat /tmp/consolidated/{{ inventory_hostname }}_precheck/{{ item }}') }}"
        postch: "{{ query('lines','cat /tmp/consolidated/{{ inventory_hostname }}_postcheck/{{ item }}') }}"
      with_items: "{{ files_to_copy.stdout_lines }}"
      shell: |
        echo -e "{{ item }} - YES" >> /tmp/{{ inventory_hostname }}_Comparison

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...