[ideology] 1. This script can test hundreds of the ansible roles in upstream git repo. 2. ansible roles are supported for the EL platform which has 11257 results in ansible-galaxy official website. 3. For testing ansible git repo, those cannot be tested in a unified way, I mainly test ansible roles git repo, and these roles repo will be more and more.
[why] Command "ansible-playbook site.yml" can run in localhost, and only need to create an entry YAML file in which the value of hosts is localhost, for example "site.yml", created in the directory at the same level as the roles directory, which can invoke roles in it. And it dose not need to create a host file in $ansible_path.
``` site.yml --- - hosts: localhost roles: - roles: ansible-role-nginx ``` ansible-role-nginx which is an role in ~/.ansible/roles, can install from galaxy or git clone from github.
Signed-off-by: Zhang Yale ylzhangah@qq.com --- tests/ansible_test | 92 ++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 39 deletions(-)
diff --git a/tests/ansible_test b/tests/ansible_test index 09e5ca9e..703f5c55 100755 --- a/tests/ansible_test +++ b/tests/ansible_test @@ -1,59 +1,73 @@ #!/bin/bash -# username -# rolename -# ansible_host -# ansible_user -# ansible_python_interpreter - -[ -n "$username" ] || echo "username is empty" -[ -n "$rolename" ] || echo "rolename is empty" -[ -n "$ansible_host" ] || $ansible_host=localhost -[ -n "$ansible_user" ] || $ansible_user=root -[ -n "$ansible_python_interpreter" ] || $ansible_python_interpreter=/user/bin/python3 - -build_mutual_trust() +# - ansible_repo + +. $LKP_SRC/lib/debug.sh + +check_vars() { - echo -e "y\n" | ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa - cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys - ssh -o "StrictHostKeyChecking=no" -o "ExitOnForwardFailure=yes" -o "passwordAuthentication=no" root@$ansible__host 'chmod 600 ~/.ssh/authorized_keys' + ansible_host=localhost + + [ -n "$ansible_repo" ] || die "ansible_repo is empty" + benchmark=${ansible_repo##*/} + + ansible_path=/root/.ansible + [ -d "$ansible_path" ] || mkdir -p /root/.ansible }
install_ansible() { - pip3 install ansible - ansible localhost -m ping - #ansible all -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}' path=/root/.ssh/authorized_keys manage_dir=no" --ask-pass -c paramiko - [ $? -eq 0 ] && echo "Ansible is successfully deployed!" + [[ "$os" == "openeuler" ]] && pip3 install ansible + [[ "$os" == "centos" ]] && yum install -y ansible + [[ "$os" == "debian" ]] && apt-get install -y ansible + + command -v ansible > /dev/null && { + ansible localhost -m ping + [ $? -eq 0 ] && { + echo "Ansible is successfully deployed!" + } + } }
download_ansible_role() { - ansible-galaxy install $username.$rolename - [ $? -eq 0 ] && echo "Please check whether your rolename is correct!" + ansible_roles_path=$ansible_path/roles + [ -d $ansible_roles_path ] || mkdir -p $ansible_roles_path + cd $ansible_roles_path + git clone https://github.com/$ansible_repo.git || exit + # git clone git://$GIT_SERVER/$ansible_repo.git || exit + # ansible-galaxy install $username.$rolename + if [ $? -eq 0 ]; then + echo "$benchmark is successfully installed" + else + echo "Please check whether your ansible_repo is correct!" + fi }
ansible_playbook_run() { - ansible_path=/root/.ansible - [ -d "$ansible_path" ] || mkdir -p /root/.ansible - cat <<-EOF > "$ansible_path"/hosts - $ansible_host ansible_user=$ansible_user ansible_python_interpreter=$ansible_python_interpreter - EOF - [ $? -eq 0 ] && echo "Hostfile has been generated!" - - cat <<-EOF > "$ansible_path"/$rolename.yml + cat <<-EOF > "$ansible_path"/site.yml - hosts: $ansible_host - remote_user: $ansible_user roles: - - role: $username.$rolename + - role: $benchmark EOF - [ $? -eq 0 ] && echo "Playbook has been generated!" + [ $? -eq 0 ] && { + echo "Playbook has been generated!" + } + + ansible-playbook "$ansible_path"/site.yml
- ansible-playbook "$ansible_path"/$rolename.yml - [ $? -eq 0 ] && echo "Your playbook is running successfully!" + if [ $? -eq 0 ]; then + echo "Your playbook is running successfully!" + else + echo "playbook.run.fail: 1" && exit 1 +} + +main() +{ + check_vars + install_ansible + download_ansible_role + ansible_playbook_run }
-#build_mutual_trust -install_ansible -download_ansible_role -ansible_playbook_run +main
On Wed, Jan 20, 2021 at 11:36:04AM +0800, Zhang Yale wrote:
Pls ignore this email, thanks
[ideology]
- This script can test hundreds of the ansible roles in upstream git repo.
- ansible roles are supported for the EL platform which has 11257 results in ansible-galaxy official website.
- For testing ansible git repo, those cannot be tested in a unified way,
I mainly test ansible roles git repo, and these roles repo will be more and more.
[why] Command "ansible-playbook site.yml" can run in localhost, and only need to create an entry YAML file in which the value of hosts is localhost, for example "site.yml", created in the directory at the same level as the roles directory, which can invoke roles in it. And it dose not need to create a host file in $ansible_path.
site.yml --- - hosts: localhost roles: - roles: ansible-role-nginx
ansible-role-nginx which is an role in ~/.ansible/roles, can install from galaxy or git clone from github.
Signed-off-by: Zhang Yale ylzhangah@qq.com
tests/ansible_test | 92 ++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 39 deletions(-)
diff --git a/tests/ansible_test b/tests/ansible_test index 09e5ca9e..703f5c55 100755 --- a/tests/ansible_test +++ b/tests/ansible_test @@ -1,59 +1,73 @@ #!/bin/bash -# username -# rolename -# ansible_host -# ansible_user -# ansible_python_interpreter
-[ -n "$username" ] || echo "username is empty" -[ -n "$rolename" ] || echo "rolename is empty" -[ -n "$ansible_host" ] || $ansible_host=localhost -[ -n "$ansible_user" ] || $ansible_user=root -[ -n "$ansible_python_interpreter" ] || $ansible_python_interpreter=/user/bin/python3
-build_mutual_trust() +# - ansible_repo
+. $LKP_SRC/lib/debug.sh
+check_vars() {
- echo -e "y\n" | ssh-keygen -t rsa -b 2048 -N '' -f /root/.ssh/id_rsa
- cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
- ssh -o "StrictHostKeyChecking=no" -o "ExitOnForwardFailure=yes" -o "passwordAuthentication=no" root@$ansible__host 'chmod 600 ~/.ssh/authorized_keys'
- ansible_host=localhost
- [ -n "$ansible_repo" ] || die "ansible_repo is empty"
- benchmark=${ansible_repo##*/}
- ansible_path=/root/.ansible
- [ -d "$ansible_path" ] || mkdir -p /root/.ansible
}
install_ansible() {
- pip3 install ansible
- ansible localhost -m ping
- #ansible all -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}' path=/root/.ssh/authorized_keys manage_dir=no" --ask-pass -c paramiko
- [ $? -eq 0 ] && echo "Ansible is successfully deployed!"
- [[ "$os" == "openeuler" ]] && pip3 install ansible
- [[ "$os" == "centos" ]] && yum install -y ansible
- [[ "$os" == "debian" ]] && apt-get install -y ansible
- command -v ansible > /dev/null && {
ansible localhost -m ping
[ $? -eq 0 ] && {
echo "Ansible is successfully deployed!"
}
- }
}
download_ansible_role() {
- ansible-galaxy install $username.$rolename
- [ $? -eq 0 ] && echo "Please check whether your rolename is correct!"
- ansible_roles_path=$ansible_path/roles
- [ -d $ansible_roles_path ] || mkdir -p $ansible_roles_path
- cd $ansible_roles_path
- git clone https://github.com/$ansible_repo.git || exit
- # git clone git://$GIT_SERVER/$ansible_repo.git || exit
- # ansible-galaxy install $username.$rolename
- if [ $? -eq 0 ]; then
echo "$benchmark is successfully installed"
- else
echo "Please check whether your ansible_repo is correct!"
- fi
}
ansible_playbook_run() {
- ansible_path=/root/.ansible
- [ -d "$ansible_path" ] || mkdir -p /root/.ansible
- cat <<-EOF > "$ansible_path"/hosts
- $ansible_host ansible_user=$ansible_user ansible_python_interpreter=$ansible_python_interpreter
- EOF
- [ $? -eq 0 ] && echo "Hostfile has been generated!"
- cat <<-EOF > "$ansible_path"/$rolename.yml
- cat <<-EOF > "$ansible_path"/site.yml
- hosts: $ansible_host
roles:remote_user: $ansible_user
- role: $username.$rolename
EOF- role: $benchmark
- [ $? -eq 0 ] && echo "Playbook has been generated!"
- [ $? -eq 0 ] && {
echo "Playbook has been generated!"
}
ansible-playbook "$ansible_path"/site.yml
ansible-playbook "$ansible_path"/$rolename.yml
- [ $? -eq 0 ] && echo "Your playbook is running successfully!"
- if [ $? -eq 0 ]; then
echo "Your playbook is running successfully!"
- else
echo "playbook.run.fail: 1" && exit 1
+}
+main() +{
- check_vars
- install_ansible
- download_ansible_role
- ansible_playbook_run
}
-#build_mutual_trust -install_ansible -download_ansible_role -ansible_playbook_run
+main
2.23.0