Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.74 KB | None | 0 0
  1. ansible --version
  2. ansible 2.7.10
  3. python version = 2.7.5
  4.  
  5. #Remote software version
  6. cat /path/to/version_file.txt
  7. FullVersion=12.52.105.2112
  8.  
  9. #Playbook Install/upgrades firmare on remote nodes
  10. #
  11. ---
  12.  
  13. - hosts: "RedHat_7_nodes"
  14. remote_user: test_user
  15. connection: ssh
  16. gather_facts: '{{ gather }}'
  17.  
  18. # Next Section - Variables
  19.  
  20. vars_prompt:
  21.  
  22. - name: EXPECTED_REMOTE_SOFTWARE_VERSION
  23. prompt: What is expected version of Software? (If remote server is already at that level, this playbook will skip it)
  24. private: no
  25.  
  26. tasks:
  27.  
  28. - name: Check if the remote Software version is below "{{ EXPECTED_REMOTE_SOFTWARE_VERSION }}"
  29. shell: grep FullVersion /path/to/version_file.txt | awk -F = '{print $2}'
  30. check_mode: no
  31. register: CURRENT_INSTALLED_VERSION
  32.  
  33. - debug:
  34. msg: "{{ CURRENT_INSTALLED_VERSION }}"
  35. - meta: end_play
  36. when: CURRENT_INSTALLED_VERSION.stdout | version(EXPECTED_REMOTE_SOFTWARE_VERSION,'>=')
  37.  
  38. - name: Run the binary and upgrade since the installed version is lower than intended software version
  39. shell: echo "Run the binary and upgrade since the installed version is lower than intended software version "
  40. check_mode: no
  41.  
  42. #Runtime 1. Expected version is lower than installed version. Skip this host. No upgrade.
  43.  
  44. 14:36:32-ram@thinkred1cartoon:~/Dropbox/Ansible/version_check$ ansible-playbook WebAgent_Install.yml -i Global_hosts_inventory.txt --extra-vars "gather=yes"
  45. What is expected version of Software? (If remote server is already at that level, this playbook will skip it): 12.52.105.2111
  46.  
  47. PLAY [RedHat_7_nodes] ************************************************************************************************************************************************************************
  48.  
  49. TASK [Gathering Facts] ***********************************************************************************************************************************************************************
  50. ok: [joker7.cartoon.biz]
  51.  
  52. TASK [Check if the remote Software version is below "12.52.105.2111"] ************************************************************************************************************************
  53. changed: [joker7.cartoon.biz]
  54.  
  55. TASK [debug] *********************************************************************************************************************************************************************************
  56. ok: [joker7.cartoon.biz] => {
  57. "msg": {
  58. "changed": true,
  59. "cmd": "grep FullVersion /path/to/version_file.txt | awk -F = '{print $2}'",
  60. "delta": "0:00:00.013802",
  61. "end": "2019-05-16 14:37:00.635365",
  62. "failed": false,
  63. "rc": 0,
  64. "start": "2019-05-16 14:37:00.621563",
  65. "stderr": "",
  66. "stderr_lines": [],
  67. "stdout": "12.52.105.2112",
  68. "stdout_lines": [
  69. "12.52.105.2112"
  70. ]
  71. }
  72. }
  73. [DEPRECATION WARNING]: Using tests as filters is deprecated. Instead of using `result|version` use `result is version`. This feature will be removed in version 2.9. Deprecation warnings can
  74. be disabled by setting deprecation_warnings=False in ansible.cfg.
  75.  
  76. PLAY RECAP ***********************************************************************************************************************************************************************************
  77. joker7.cartoon.biz : ok=3 changed=1 unreachable=0 failed=0
  78.  
  79. #Runtime - 2. Expected version is higher than installed version. Upgrade.
  80.  
  81. 14:35:30-ram@thinkred1cartoon:~/Dropbox/Ansible/version_check$ ansible-playbook WebAgent_Install.yml -i Global_hosts_inventory.txt --extra-vars "gather=yes"
  82. What is expected version of Software? (If remote server is already at that level, this playbook will skip it) [12.52.105.2112]: 12.52.105.2113
  83.  
  84. PLAY [RedHat_7_nodes] ************************************************************************************************************************************************************************
  85.  
  86. TASK [Gathering Facts] ***********************************************************************************************************************************************************************
  87. ok: [joker7.cartoon.biz]
  88.  
  89. TASK [Check if the remote Software version is below "12.52.105.2113"] ************************************************************************************************************************
  90. changed: [joker7.cartoon.biz]
  91.  
  92. TASK [debug] *********************************************************************************************************************************************************************************
  93. ok: [joker7.cartoon.biz] => {
  94. "msg": {
  95. "changed": true,
  96. "cmd": "grep FullVersion /path/to/version_file.txt | awk -F = '{print $2}'",
  97. "delta": "0:00:00.013155",
  98. "end": "2019-05-16 14:35:49.364318",
  99. "failed": false,
  100. "rc": 0,
  101. "start": "2019-05-16 14:35:49.351163",
  102. "stderr": "",
  103. "stderr_lines": [],
  104. "stdout": "12.52.105.2112",
  105. "stdout_lines": [
  106. "12.52.105.2112"
  107. ]
  108. }
  109. }
  110. [DEPRECATION WARNING]: Using tests as filters is deprecated. Instead of using `result|version` use `result is version`. This feature will be removed in version 2.9. Deprecation warnings can
  111. be disabled by setting deprecation_warnings=False in ansible.cfg.
  112.  
  113. TASK [Run the binary and upgrade since the installed version is lower than intended software version] ****************************************************************************************
  114. changed: [joker7.cartoon.biz]
  115.  
  116. PLAY RECAP ***********************************************************************************************************************************************************************************
  117. joker7.cartoon.biz : ok=4 changed=2 unreachable=0 failed=0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement