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

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
```
8 changes: 4 additions & 4 deletions utils/ansible/configure-pmem.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2023, Intel Corporation
# Copyright 2023-2024, Intel Corporation

# This playbook is designed to configure regions and namespaces on DIMMs
# so users can execute tests later. Playbook usage is described in
Expand Down Expand Up @@ -28,14 +28,14 @@
#
# 2) locally
# For a playbook to be used on a local server please log in as pmdkuser:
# a) comment out the first command: # -hosts: "{{ host }}"
# a) comment out the first command: # - hosts: "{{ host }}"
# b) uncomment the next two lines:
# - 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
6 changes: 3 additions & 3 deletions utils/ansible/configure-self-hosted-runner.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2023, Intel Corporation
# Copyright 2023-2024, Intel Corporation

# This playbook is designed to add a new self-hosted runner to pmem/pmdk.
# Examples below show how to use this file:
Expand All @@ -16,7 +16,7 @@
#
# 2) locally
# For a playbook to be used on a local server please log in as pmdkuser:
# a) comment out the first command: # -hosts: "{{ host }}"
# a) comment out the first command: # - hosts: "{{ host }}"
# b) uncomment the next two lines:
# - hosts: localhost
# connection: local
Expand All @@ -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
21 changes: 16 additions & 5 deletions utils/ansible/opensuse-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
# 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 locally:
#
# 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 @@ -162,8 +173,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 @@ -173,7 +184,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
21 changes: 16 additions & 5 deletions utils/ansible/rockylinux-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
# 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 locally:
#
# 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 @@ -157,13 +168,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
4 changes: 2 additions & 2 deletions utils/ansible/update-os.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2023, Intel Corporation
# Copyright 2023-2024, Intel Corporation

# This playbook is designed to update all installed packages at
# Rocky Linux / OpenSUSE and reboot the platform if required.
# The playbook description and how to use it are available
# 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 an immediate system reboot.

- hosts: localhost
connection: local
Expand Down
Loading