0

I have item list of IPs:

server_hosts: - { host: '1.1.1.1' } - { host: '10.10.10.10' } 

I want to pass only one of the items in the command line:

ansible-playbook base.yml -i ${host}, --extra-vars "env_name=lab server_hosts={host:'${1.1.1.1}'} " 

but this gives an error of:

{"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode' object has no attribute 'host'\n\nThe error

Any advice how to pass a specific item from list in the command line?

5
  • It wouldn't hurt if you also revealed what shell you were using, because bash will stumble on this command. Yet ${host} looks bash-like. Commented Dec 26, 2016 at 12:59
  • the command is editted here, but it passes and run the pre tasks ( from jenkins) but fail on the task using the list items Commented Dec 26, 2016 at 13:02
  • I repeat: bash will return bad substitution when you try to execute it. Please edit your question to include a verifiable example. Right now it's a pure fabrication and you are only wasting readers' time. Commented Dec 26, 2016 at 13:13
  • Not to mention the title has nothing to do with the content of the question. You don't even bother to show what you run with_items. Commented Dec 26, 2016 at 13:22
  • I have removed the host from server_hosts: - { host: '1.1.1.1' } - { host: '10.10.10.10' } and this accepted the server_hosts='{1.1.1.1}' in the cmd. FYI Commented Dec 26, 2016 at 14:42

1 Answer 1

1

Please pay attention to a side note here:

Note: Values passed in using the key=value syntax are interpreted as strings. Use the JSON format if you need to pass in anything that shouldn’t be a string (Booleans, integers, floats, lists etc).

So, you should use:

--extra-vars '{"env_name":"lab","server_hosts":{"host":"1.1.1.1"}}' 

Otherwise you end up with server_hosts as string, not an object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.