Re: [ansible-project] Passing json in shell module in ansible

89 views
Skip to first unread message
Message has been deleted

Dick Visser

unread,
Feb 23, 2022, 12:32:58 PM2/23/22
to ansible...@googlegroups.com
Can you confirm that the exact same command (without single quotes around it) actually works from an interactive shell?

On Wed, 23 Feb 2022 at 18:13, Shivani Arora <shiva...@gmail.com> wrote:
Hi All,

I need help with passing JSON in the shell module in ansible. 

Playbook - 

- hosts: localhost
  name: refresh asg
  connection: local
  gather_facts: True
  tasks:
  - name: refresh instances
    shell: 'aws autoscaling start-instance-refresh --region=us-east-1 --auto-scaling-group-name test_asg --preferences '{"InstanceWarmup": 400, "MinHealthyPercentage": 50}'

The error I'm getting is -

fatal: [localhost]: FAILED! => {"changed": true, "cmd": "aws autoscaling start-instance-refresh --region=us-east-1 --auto-scaling-group-name Test_Iwo_nodes_Development_zone3 --preferences {\"MinHealthyPercentage\":90,\"InstanceWarmup\":180}", "delta": "0:00:01.069908", "end": "2022-02-23 08:40:31.459081", "msg": "non-zero return code", "rc": 255, "start": "2022-02-23 08:40:30.389173", "stderr": "usage: \rNote: AWS CLI version 2, the latest major version of the AWS CLI, is now stable and recommended for general use. For more information, see the AWS CLI version 2 installation instructions at: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html\n\nusage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]\nTo see help text, you can run:\n\n  aws help\n  aws <command> help\n  aws <command> <subcommand> help\n\nUnknown options: InstanceWarmup:180", "stderr_lines": ["usage: ", "Note: AWS CLI version 2, the latest major version of the AWS CLI, is now stable and recommended for general use. For more information, see the AWS CLI version 2 installation instructions at: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html", "", "usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]", "To see help text, you can run:", "", "  aws help", "  aws <command> help", "  aws <command> <subcommand> help", "", "Unknown options: InstanceWarmup:180"], "stdout": "", "stdout_lines": []}

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a36daf18-cc83-4e4c-86f0-6539f3f78f64n%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.
Message has been deleted

Dick Visser

unread,
Feb 24, 2022, 3:08:38 AM2/24/22
to ansible...@googlegroups.com
I would supply it as a yaml formatted variable to your task and then use the filter combo to_json|quote 

At least that's how I supply crazy complex dicts on aws cli commands and those work 

On Thu, 24 Feb 2022 at 05:54, Shivani Arora <shiva...@gmail.com> wrote:
The following command works in an interactive shell - 

aws autoscaling start-instance-refresh  --auto-scaling-group-name Test_Iwo_nodes_Development_zone1 --preferences '{"InstanceWarmup": 400, "MinHealthyPercentage": 50}'

Please let me know, how should I pass this in shell module within ansible?

Thanks

Brian Coca

unread,
Mar 16, 2022, 6:14:09 PM3/16/22
to Ansible Project
easiest way:

shell: !unsafe aws autoscaling start-instance-refresh
--auto-scaling-group-name Test_Iwo_nodes_Development_zone1
--preferences '{"InstanceWarmup": 400, "MinHealthyPercentage": 50}'

but breaking it down into variables is still a good idea, you only
need `!unsafe` on the 'dictionary looking' parts.

--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages