ansible变量可用于在剧本中声明主机吗?

时间:2018-07-25 13:10:22

标签: ansible yaml ansible-template ansible-tower

所以本质上我想做的是:

有以下格式的剧本

UIImageView imageView = new UIImageView(); 
imageView.Layer.BorderWidth = 5f; //set border thickness
imageView.Layer.CornerRadius = 25; //make corner's rounded
imageView.Layer.BorderColor = UIColor.Red.CGColor; //set border color red
imageView.Image = new UIImage(imgPath); //set img
imageView.ClipsToBounds = true; //required - so image is rounded

其中myIP和ThePackageIWantToInstall可用。

,当运行作业模板时,我希望 EXTRA VARIABLES 弹出窗口中的用户能够进入

myIP = 192.168.1.1 ThePackageIWantToInstall = nano

这可能是因为文档中没有提供通过作业模板提供变量的示例吗?

2 个答案:

答案 0 :(得分:1)

是的

- name: Do The Thing
  hosts: "{{ foo }}"
  roles:
   - "{{ role }}"

需要胡须和引号。


从弹出窗口运行

(我不使用它,但是建议将其作为编辑,谢谢...)

foo:值

答案 1 :(得分:0)

我用add_hosts实现了类似的目的。在这里,我不是安装软件包,而是使用从命令行传递的名称创建文件。可以从命令行传递任意数量的主机(以逗号分隔)。

# cat addhost2.yml
- hosts: localhost
  gather_facts: no
  tasks:
    - add_host:
        name: "{{ item }}"
        groups: hosts_from_commandline
      with_items: "{{ new_hosts_passed.split(',') }}"


- hosts: hosts_from_commandline
  tasks:
    - name: Ansible create file with name passed from commandline
      file:
        path: "/tmp/{{ filename_from_commandline }}"
        state: touch
# ansible-playbook -i hosts addhost2.yml --extra-vars='new_hosts_passed=192.168.3.104,192.168.3.113 filename_from_commandline=lathamdkv'

希望这会有所帮助

相关问题