【问题标题】:Set git email based on read entry from bash script根据 bash 脚本中的读取条目设置 git 电子邮件
【发布时间】:2018-09-06 07:03:06
【问题描述】:

我有一个调用多个 .sh 脚本的 ansible playbook,这个失败是因为它没有正确设置,这是我第一次使用 read 并且不知道如何正确使用它。

#!/bin/bash
echo "Please set your email address, stuff it up? enter git config    user.email";
read ea;
git config --global user.email $ea;
exit;

我想要它做的,因为目前它完全跳过这个或只是错误,是要求用户输入他们的电子邮件地址并将 git 电子邮件设置为该输入并继续剧本的其余部分。 完成

【问题讨论】:

标签: bash git ansible


【解决方案1】:
- hosts: localhost
  gather_facts: no
  become: no
  vars_prompt:
    - name: git_email
      prompt: Please enter your email address for use with git commits
      private: no
  tasks:
  - shell: |
      git config --global core.email "{{ git_email }}"

并且,根据精美的手册,他们可以通过使用 --extra-vars '{"git_email": "bob@example.com"}' 运行 ansible-playbook 来绕过该提示

【讨论】:

  • 这很好,但是“git_email”不存储提示输入的内容,并且在执行时不输出该条目
  • 我在发布之前亲自执行了该代码 sn-p,包括有和没有 extra-vars 位。请随时使用您遇到的错误更新您的问题,我们会尽力解决
  • 它提示得很好,然后它很清楚地打印到终端“git config --global user.email "{{ git_email }}"" 并在使用 git config user.email 进行检查时出现"{{ git_email }}" vars_prompt: - name: git_email prompt: 请输入您的 DJR 电子邮件地址。私人:没有任务:-外壳:| git config --global user.email "{{ git_email }}"
  • 人们会注意到我说“更新你的问题”,因为试图阅读评论中的文本输出很痛苦
  • 错误是我在提示出现时输入的值没有存储在任何地方,也没有存储在“git_email”中,所以当它实际运行该命令来设置它时,它实际上只有那些词“git_email”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-30
  • 2018-01-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多