How to use command stdin in Ansible?

前端 未结 3 1683
别那么骄傲
别那么骄傲 2020-12-21 04:16

I\'ve tried this:

- name: Log into Docker registry
  command: docker login --username \"{{ docker_registry_username }}\" --password-stdin
  stdin: \"{{ docke         


        
相关标签:
3条回答
  • 2020-12-21 04:52

    If you want to use the stdin argument to the command module, take a look at the docs, which show examples using other options such as creates, which looks like this:

    # You can also use the 'args' form to provide the options.
    - name: This command will change the working directory to somedir/ and will only run when /path/to/database doesn't exist.
      command: /usr/bin/make_database.sh arg1 arg2
      args:
        chdir: somedir/
        creates: /path/to/database
    

    For your use case, you would want:

    - name: Log into Docker registry
      command: docker login --username "{{ docker_registry_username }}" --password-stdin
      args:
        stdin: "{{ docker_registry_password }}"
    

    Your first attempt failed because you were setting stdin as a key at the task level (like when or ignore_errors, etc), when you actually want it to be an argument to the command module.

    Your second attempt failed because it wasn't valid YAML.

    0 讨论(0)
  • 2020-12-21 05:02

    Why do you use command/shell to log into Docker registry? Ansible has docker_login module for that: https://docs.ansible.com/ansible/latest/modules/docker_login_module.html it's in preview, from community, but it works.

    You can create vault file with sensitive data.

    0 讨论(0)
  • 2020-12-21 05:10

    Sounds like you want to use the Ansible expect module. See https://docs.ansible.com/ansible/latest/modules/expect_module.html.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题