আমি উপরের সমস্ত বিকল্পগুলি উত্তরযোগ্য ২.৪.১.০ দিয়ে চেষ্টা করেছি এবং অন্য দু'জন অবধি কেউ কাজ করে না এবং এখানে কেসটি পুনঃ উত্পাদন করার জন্য বিস্তারিত রয়েছে detail
$ cat ~/.bash_aliases
alias ta="echo 'this is test for ansible interactive shell'";
এবং এটি উত্তরযোগ্য পরীক্ষা :
- name: Check the basic string operations
hosts: 127.0.0.1
connection: local
tasks:
- name: Test Interactive Bash Failure
shell: ta
ignore_errors: True
- name: Test Interactive Bash Using Source
shell: source ~/.bash_aliases && ta
args:
executable: /bin/bash
ignore_errors: yes
- name: Test Interactive Bash Using .
shell: . ~/.bash_aliases && ta
ignore_errors: yes
- name: Test Interactive Bash Using /bin/bash -ci
shell: /bin/bash -ic 'ta'
register: result
ignore_errors: yes
- debug: msg="{{ result }}"
- name: Test Interactive Bash Using sudo -ui
shell: sudo -ui hearen ta
register: result
ignore_errors: yes
- name: Test Interactive Bash Using ssh -tt localhost /bin/bash -ci
shell: ssh -tt localhost /bin/bash -ci 'ta'
register: result
ignore_errors: yes
এবং এই ফলাফল:
$ ansible-playbook testInteractiveBash.yml
[WARNING]: Could not match supplied host pattern, ignoring: all
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [Check the basic string operations] ************************************************************************************************************************************************
TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [127.0.0.1]
TASK [Test Interactive Bash Failure] ****************************************************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": "ta", "delta": "0:00:00.001341", "end": "2018-10-31 10:11:39.485897", "failed": true, "msg": "non-zero return code", "rc": 127, "start": "2018-10-31 10:11:39.484556", "stderr": "/bin/sh: 1: ta: not found", "stderr_lines": ["/bin/sh: 1: ta: not found"], "stdout": "", "stdout_lines": []}
...ignoring
TASK [Test Interactive Bash Using Source] ***********************************************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": "source ~/.bash_aliases && ta", "delta": "0:00:00.002769", "end": "2018-10-31 10:11:39.588352", "failed": true, "msg": "non-zero return code", "rc": 127, "start": "2018-10-31 10:11:39.585583", "stderr": "/bin/bash: ta: command not found", "stderr_lines": ["/bin/bash: ta: command not found"], "stdout": "", "stdout_lines": []}
...ignoring
TASK [Test Interactive Bash Using .] ****************************************************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": ". ~/.bash_aliases && ta", "delta": "0:00:00.001425", "end": "2018-10-31 10:11:39.682609", "failed": true, "msg": "non-zero return code", "rc": 127, "start": "2018-10-31 10:11:39.681184", "stderr": "/bin/sh: 1: ta: not found", "stderr_lines": ["/bin/sh: 1: ta: not found"], "stdout": "", "stdout_lines": []}
...ignoring
TASK [Test Interactive Bash Using /bin/bash -ci] ****************************************************************************************************************************************
changed: [127.0.0.1]
TASK [debug] ****************************************************************************************************************************************************************************
ok: [127.0.0.1] => {
"msg": {
"changed": true,
"cmd": "/bin/bash -ic 'ta'",
"delta": "0:00:00.414534",
"end": "2018-10-31 10:11:40.189365",
"failed": false,
"rc": 0,
"start": "2018-10-31 10:11:39.774831",
"stderr": "",
"stderr_lines": [],
"stdout": "this is test for ansible interactive shell",
"stdout_lines": [
"this is test for ansible interactive shell"
]
}
}
TASK [Test Interactive Bash Using sudo -ui] *********************************************************************************************************************************************
[WARNING]: Consider using 'become', 'become_method', and 'become_user' rather than running sudo
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": "sudo -ui hearen ta", "delta": "0:00:00.007906", "end": "2018-10-31 10:11:40.306128", "failed": true, "msg": "non-zero return code", "rc": 1, "start": "2018-10-31 10:11:40.298222", "stderr": "sudo: unknown user: i\nsudo: unable to initialize policy plugin", "stderr_lines": ["sudo: unknown user: i", "sudo: unable to initialize policy plugin"], "stdout": "", "stdout_lines": []}
...ignoring
TASK [Test Interactive Bash Using ssh -tt localhost /bin/bash -ci] **********************************************************************************************************************
hearen@localhost's password:
changed: [127.0.0.1]
PLAY RECAP ******************************************************************************************************************************************************************************
127.0.0.1 : ok=8 changed=6 unreachable=0 failed=0
দুটি বিকল্প কাজ করেছে:
shell: /bin/bash -ic 'ta'
shell: ssh -tt localhost /bin/bash -ci 'ta'
তবে এটির জন্য স্থানীয়ভাবে পাসওয়ার্ড ইনপুট দরকার।
source
আপনি যখন এটি কোনও বিদ্যমান শেলের ভিতরে চালাবেন কেবল তখনই তা বোধগম্য হয় - এটি সেই শেলের মধ্যে কমান্ডগুলি চালায় এবং যখন এমন কোনও শেল থাকে যার অবস্থা বা কনফিগারেশন আপনি পরিবর্তন করতে চান তখন কেবল কার্যকর / সহায়ক হয়। আপনি যখন কোনও জবাবদিহিমূলক ক্রিয়াটি চালান, এটি সম্পূর্ণ নতুন শেল তৈরি করে এবং সেই শেলের ভিতরে একটি কমান্ড চালায় - সুতরাং আপনি অন্য কোনও প্রসঙ্গে পরিবেশের পরিবর্তনশীলগুলি আপডেট করবেন না, সুতরাং এটিতে কোনও কার্যকর / দীর্ঘস্থায়ী ছাপ নেই have এমনকি যদি ত্রুটি ছাড়াই এটি চালাতে পেলেন।