Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
Created March 24, 2021 07:43
Show Gist options
  • Save heiwa4126/b23ba838f0cd2600fe378ecb0d8c3a33 to your computer and use it in GitHub Desktop.
Save heiwa4126/b23ba838f0cd2600fe378ecb0d8c3a33 to your computer and use it in GitHub Desktop.
andibleのexpectモジュールの練習。微妙なコツがいるのがめんどくさい
# andibleのexpectモジュールの練習
# r7のfoobarユーザのパスワードをpasswdコマンドで変えてみる
# - 事前にfoobarユーザは作ってあるものとする(useradd foobar)
# - テストが終わったらfoobarユーザは消すこと(userdel foobar)
#
# # passwd foobar
# Changing password for user foobar.
# New password:
# Retype new password:
# passwd: all authentication tokens updated successfully.
- name: update foobar's password
hosts: r7
become: true
gather_facts: false
vars:
foobar_passwd: Tarako7kagaMi
# TODO: パスワードを直書きするな
tasks:
- expect:
command: /bin/bash -c "LANG=C passwd foobar"
timeout: 5
responses:
'New password:' : "{{ foobar_passwd }}"
'Retype new password:': "{{ foobar_passwd }}"
register: rc
changed_when: true
- debug: var=rc.stdout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment