Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common: ansible_user support in ansible scripts #6055

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions utils/ansible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export SETUP_SCRIPT= # opensuse-setup.yml or rockylinux-setup.yml

ansible-playbook -i $TARGET_IP, $SETUP_SCRIPT \
--extra-vars "host=all ansible_user=root ansible_password=$ROOT_PASSWORD \
testUser=pmdkuser testUserPass=pmdkpass"
new_user=pmdkuser new_user_pass=pmdkpass"
```
**Note**: If the Linux kernel is outdated, `opensuse-setup.yml` and
`rockylinux-setup.yml` playbooks will reboot the target platform.
Expand Down Expand Up @@ -111,6 +111,11 @@ ansible-playbook -i $TARGET_IP, configure-self-hosted-runner.yml --extra-vars

# Provisioning from the target platform itself
It is possible to run playbooks directly on the target platform.
In this case, you have to always pass `ansible_user=pmdkuser` as an additional
variable since the playbooks are fine-tuned for remote execution and assume
the `ansible_user` variable is defined. When running on a remote target the
connection plugin does it for you.

To run playbooks inside the platform please comment out the line:
```
- hosts: "{{ host }}"
Expand All @@ -123,18 +128,18 @@ uncomment the following two:
and run commands as follows e.g.
```sh
export SETUP_SCRIPT= # opensuse-setup.yml or rockylinux-setup.yml
sudo ansible-playbook $SETUP_SCRIPT --extra-vars "testUser=pmdkuser"
sudo ansible-playbook $SETUP_SCRIPT --extra-vars "new_user=pmdkuser"
```
**Note**: If a reboot is necessary, as described above, perform it manually and
rerun the playbook without in question.

And next log in as `pmdkuser`:
```sh
ansible-playbook configure-pmem.yml --extra-vars "newRegions=true"
ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser newRegions=true"
# you will have to perform a reboot manually
sudo reboot
# and re-run the playbook without newRegions=true to finalize the setup
ansible-playbook configure-pmem.yml
ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser"
```

# Example - GitHub self-hosted runner setup
Expand All @@ -156,30 +161,30 @@ Update playbooks to be used directly on the target as described [above](#provisi
and execute:
```sh
# as root:
ansible-playbook rockylinux-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
ansible-playbook rockylinux-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass"
# reboot shall be performed only if the playbook requests to do it.
reboot
# ...
cd pmdk/utils/ansible
ansible-playbook rockylinux-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
ansible-playbook rockylinux-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass"
```
Log in as `pmdkuser` and execute:
```sh
# as pmdkuser
cd pmdk/utils/ansible
ansible-playbook configure-pmem.yml --extra-vars "newRegions=true"
ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser newRegions=true"
sudo reboot
# ...
cd pmdk/utils/ansible
# note - no newRegions=true when running the playbook after the reboot
ansible-playbook configure-pmem.yml
ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser"

export GHA_TOKEN= # GitHub token generated for a new self-hosted runner
export HOST_NAME=`hostname`
export LABELS=rhel
export VARS_GHA=http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912
ansible-playbook configure-self-hosted-runner.yml -extra-vars \
"runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
"ansible_user=pmdkuser runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
cd
rm -rf pmdk
```
Expand All @@ -196,30 +201,30 @@ Update playbooks to be used directly on the target as described [above](#provisi
and execute:
```sh
# as root:
ansible-playbook opensuse-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
ansible-playbook opensuse-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass"
# reboot shall be performed only if the playbook requests to do it.
reboot
# ...
cd pmdk/utils/ansible
ansible-playbook opensuse-setup.yml --extra-vars "testUser=pmdkuser testUserPass=pmdkpass"
ansible-playbook opensuse-setup.yml --extra-vars "new_user=pmdkuser new_user_pass=pmdkpass"
```
Log in as `pmdkuser` and execute:
```sh
# as pmdkuser:
cd pmdk/utils/ansible
ansible-playbook configure-pmem.yml --extra-vars "newRegions=true"
ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser newRegions=true"
sudo reboot
# ...
cd pmdk/utils/ansible
# note - no newRegions=true when running the playbook after the reboot
ansible-playbook configure-pmem.yml
ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser"

export GHA_TOKEN= # GitHub token generated for a new self-hosted runner
export HOST_NAME=`hostname`
export LABELS=opensuse
export VARS_GHA=http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912
ansible-playbook configure-self-hosted-runner.yml -extra-vars \
"runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
"ansible_user=pmdkuser runner_name=$HOST_NAME labels=$LABELS token=$GHA_TOKEN vars_gha=$VARS_GHA"
cd
rm -rf pmdk
```
4 changes: 2 additions & 2 deletions utils/ansible/configure-pmem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
# - hosts: localhost
# connection: local
# c) setup PMem for the first time (establish regions):
# ansible-playbook configure-pmem.yml --extra-vars "newRegions=true"
# ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser newRegions=true"
# d) setup PMem if it already has been initialized before:
# ansible-playbook configure-pmem.yml
# ansible-playbook configure-pmem.yml --extra-vars "ansible_user=pmdkuser"
#

- hosts: "{{ host }}"
Expand Down
2 changes: 1 addition & 1 deletion utils/ansible/configure-self-hosted-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# export LABELS= # rhel or opensuse
# export VARS_GHA=http_proxy=http://proxy-dmz.{XXX}.com:911,https_proxy=http://proxy-dmz.{XXX}.com:912
# ansible-playbook configure-self-hosted-runner.yml --extra-vars \
# "runner_name=$HOST_NAME labels=$LABELS vars_gha=$VARS_GHA token=$GHA_TOKEN"
# "ansible_user=pmdkuser runner_name=$HOST_NAME labels=$LABELS vars_gha=$VARS_GHA token=$GHA_TOKEN"
#

#
Expand Down
23 changes: 17 additions & 6 deletions utils/ansible/opensuse-setup.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2023, Intel Corporation
# Copyright 2023-2024, Intel Corporation

# This playbook is designed to install all required packages and configure
# OpenSUSE to execute tests.
# The playbook description and how to use it are available
# in the README.md file.
#
# Below is an example of how to use this file localy:
#
# a) comment out the first command:
# -hosts: "{{ host }}"
# b) uncomment the next two lines:
# - hosts: localhost
# connection: local
# and run commands as follows e.g.
# sudo ansible-playbook opensuse-setup.yml
#

- hosts: "{{ host }}"
# - hosts: localhost
# connection: local
vars:
testUser: null
testUserPass: pmdkpass
new_user: null
new_user_pass: pmdkpass

tasks:
- name: Update kernel packages
Expand Down Expand Up @@ -159,8 +170,8 @@
- name: Add new user
shell: |
#!/usr/bin/env bash
export USER={{ testUser }}
export USERPASS={{ testUserPass }}
export USER={{ new_user }}
export USERPASS={{ new_user_pass }}
useradd -m $USER
export PFILE=./password
echo $USERPASS > $PFILE
Expand All @@ -170,7 +181,7 @@
sed -i 's/# %wheel/%wheel/g' /etc/sudoers
groupadd wheel
gpasswd wheel -a $USER
when: testUser != None
when: new_user != None

- name: Set variable OS
env:
Expand Down
23 changes: 17 additions & 6 deletions utils/ansible/rockylinux-setup.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2023, Intel Corporation
# Copyright 2023-2024, Intel Corporation

# This playbook is designed to install all required packages and
# configure Rocky Linux to execute tests.
# The playbook description and how to use it are available
# in the README.md file.
#
# Below is an example of how to use this file localy:
#
# a) comment out the first command:
# -hosts: "{{ host }}"
# b) uncomment the next two lines:
# - hosts: localhost
# connection: local
# and run commands as follows e.g.
# sudo ansible-playbook rockylinux-setup.yml
#

- hosts: "{{ host }}"
# - hosts: localhost
# connection: local
vars:
testUser: null
testUserPass: pmdkpass
new_user: null
new_user_pass: pmdkpass

tasks:
- name: Update kernel packages
Expand Down Expand Up @@ -150,13 +161,13 @@
- name: Add new user
shell: |
#!/usr/bin/env bash
export USER={{ testUser }}
export USERPASS={{ testUserPass }}
export USER={{ new_user }}
export USERPASS={{ new_user_pass }}
useradd -m $USER
echo $USERPASS | passwd $USER --stdin
gpasswd wheel -a $USER
echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
when: testUser != none
when: new_user != none

- name: Set variable OS
env:
Expand Down
2 changes: 1 addition & 1 deletion utils/ansible/update-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# in the README.md file.
#
# Note: This playbook is designed to work as a composite action during test preparation steps.
# Local usage will fail the playbook run.
# Local usage might cause imidiate system reboot.

- hosts: localhost
connection: local
Expand Down