mysql_secure_installationコマンドを実行するためのプレイブックを作成しようとしています。
このコマンドはいくつかの質問をします。私はpexpectを使用していますが、「入力」をシミュレートする方法がわかりません。最初の質問は「ルートパスワードの入力」です。ルートパスワードを入力したくありません。 SQL Serverはローカルサーバーのみ可能です。
- name: "Secure MariaDB"
expect:
command: /bin/mysql_secure_installation
responses:
Question:
- '' #I want to have ansible hit enter
- 'n' # Type n
- 'y' # Type y
- 'y' # Type y
- 'y' # Type y
- 'y' # Type y
/bin/bash -c "echo"
""、コマンド、空の行を試してみましたが、以下の応答が引き続き表示されます。
FAILED! => {"changed": true, "cmd": "/bin/mysql_secure_installation", "delta": "0:00:30.128184", "end": "2018-08-29 18:54:30.983455", "msg": "non-zero return code", "rc": 1, "start": "2018-08-29 18:54:00.855271", "stdout": "\r\nNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB\r\n SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!\r\n\r\nIn order to log into MariaDB to secure it, we'll need the current\r\npassword for the root user. If you've just installed MariaDB, and\r\nyou haven't set the root password yet, the password will be blank,\r\nso you should just press enter here.\r\n\r\nEnter current password for root (enter for none): ", "stdout_lines": ["", "NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB", " SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!", "", "In order to log into MariaDB to secure it, we'll need the current", "password for the root user. If you've just installed MariaDB, and", "you haven't set the root password yet, the password will be blank,", "so you should just press enter here.", "", "Enter current password for root (enter for none): "]}
ベストアンサー1
効果がありました。一部のコンテンツは正規表現の特殊文字として認識されることがわかりました。
- name: "Secure MariaDB"
expect:
command: /bin/mysql_secure_installation
responses:
'Enter current password for root \(enter for none\): ': ''
'Set root password\? \[Y\/n\] ': 'n'
'Remove anonymous users\? \[Y\/n\] ': 'y'
'Disallow root login remotely\? \[Y\/n\] ': 'y'
'Remove test database and access to it\? \[Y\/n\] ': 'y'
'Reload privilege tables now\? \[Y\/n\] ': 'y'
echo: yes